2 Replies Latest reply on Mar 8, 2004 1:05 AM by tkmr

    I can't generate Class manipulated by javassist.

    tkmr Newbie

      I have a problem with simple usage of javassist.
      I write code as follows:

      ClassPool pool = ClassPool.getDefault();
      CtClass ct = pool.get("test.AAA");
      ct.setSuperclass(pool.get("test.special.BBB"));
      Class cls = ct.toClass();
      Object obj = cls.newInstance();

      In this case, class relations are as follows:

      In package test:
      class Base{
      }
      class AAA extends Base{
      }

      In pachage test.special:
      class BBB extends Base{
      }

      That is, I want to change SuperClass of AAA into BBB.

      but It doesn't work. It stops on calling ct.toClass() with no Exception.
      so, I can't catch Exception.
      and further, Using loadClass method of Loader class instead of toClass
      method doesn't work too. In this case, It goes through loadClass method.
      however newInstance method failed like the first code.

      Incidentally, It runs on Tomcat4.1 with Axis1.1.
      if there are some matters in using javassist with J2EE, Please let me know
      how I should use javassist.

      regards.