0 Replies Latest reply on May 5, 2013 10:06 AM by heavenkhn

    Probleme avec le Hotswap de Javassist

    heavenkhn

      import java.io.*;

       

       

      import com.sun.jdi.connect.IllegalConnectorArgumentsException;

       

       

      import javassist.util.HotSwapper;

       

       

       

       

      public class Test {

          public static void main(String[] args) {

              HotSwapper hs = null;

                          try {

                                    hs = new HotSwapper(8000);

                          } catch (IOException e) {

                                    // TODO Auto-generated catch block

                                    e.printStackTrace();

                          } catch (IllegalConnectorArgumentsException e) {

                                    // TODO Auto-generated catch block

                                    e.printStackTrace();

                          }

              new HelloWorld().print();

       

       

              File newfile = new File("bin\\logging\\HelloWorld.class");

              byte[] bytes = new byte[(int)newfile.length()];

             

              try {

                                    new FileInputStream(newfile).read(bytes);

                          } catch (FileNotFoundException e) {

                                    // TODO Auto-generated catch block

                                    e.printStackTrace();

                          } catch (IOException e) {

                                    // TODO Auto-generated catch block

                                    e.printStackTrace();

                          }

              System.out.println("** reload a logging version");

              HelloWorld hl = new HelloWorld();

              String name = hl.getClass().getName();

              System.out.println(name);

              hs.reload(name , bytes);

              new HelloWorld().print();

       

       

              newfile = new File("HelloWorld.class");

              bytes = new byte[(int)newfile.length()];

              try {

                                    new FileInputStream(newfile).read(bytes);

                          } catch (FileNotFoundException e) {

                                    // TODO Auto-generated catch block

                                    e.printStackTrace();

                          } catch (IOException e) {

                                    // TODO Auto-generated catch block

                                    e.printStackTrace();

                          }

              System.out.println("** reload the original version");

       

       

              hs.reload("HelloWorld", bytes);

              new HelloWorld().print();

          }

      }

       

       

       

      et voila ce que sa donne dans eclipse:

       

      Listening for transport dt_socket at address: 8000

      hello world

      ** reload a logging version

      HelloWorld

      Exception in thread "HotSwap" java.lang.NoClassDefFoundError: class names do not match

                at com.sun.tools.jdi.VirtualMachineImpl.redefineClasses(VirtualMachineImpl.java:331)

                at javassist.util.HotSwapper.hotswap(HotSwapper.java:250)

                at javassist.util.HotSwapper$1.run(HotSwapper.java:224)

      Exception in thread "main" java.lang.RuntimeException: failed to reload: HelloWorld

                at javassist.util.HotSwapper.reload2(HotSwapper.java:204)

                at javassist.util.HotSwapper.reload(HotSwapper.java:160)

                at Test.main(Test.java:38)

       

       

      Sachant que Hello world a le code suivant :

       

       

      public class HelloWorld {

          public void print() {

              System.out.println("hello world");

              this.x=2;

          }

         

          public int x;

      }

       

       

       

      Pourquoi ces exceptions sont-ils apparus ???

       

      Merci.