4 Replies Latest reply on Aug 2, 2003 3:10 PM by Manuel Elaraj

    Having problem reloading class in the classpool

    Manuel Elaraj Newbie

      We are looking to use JavAssist to provide a dynamic deployment Classpool. By looking at the API, it seems that this should be supported. However, when we test this functionality it does not work correctly.

      Here is some psudo code to illustrate the objective:

      ClassPath classpath;

      cp = new ClassPool(null);
      classpath = cp.appendClassPath("C:\\Projects\\javassist\\libs\\jamessage.jar");
      CtClass cc = cp.get("com.proxymed.msg");
      Class clazz;
      clazz = cc.toClass();
      testint m = (testint)clazz.newInstance();
      //Test to verify that we are calling the old loaded class
      m.say();

      //Remove library so that it can be refreshed with new version
      cp.removeClassPath(classpath);
      //Load new updated library.
      classpath = cp.appendClassPath("C:\\Projects\\javassist\\libs\\jamessageupdated.jar");
      cc = cp.get("com.proxymed.msg");
      clazz = cc.toClass();
      testint f = (testint)clazz.newInstance();
      //Method should output consistant with updated class.
      f.say();

      If you run this code. You would get a duplicate definition exception.

      Is there a way that this can done using this JavAssist.

      Thanks,
      Manuel