1 Reply Latest reply on May 23, 2003 11:18 PM by chiba

    Javassist and Tomcat 4.1

    triphop

      Hi all,

      A big thanks for this amazing little library of code. I am a developer with the babeldoc project: www.babeldoc.com. And I am trying to get the webserver/appserver that is built into javassist to run on tomcat. I am having some issues with ClassPool finding my classes:

      in the servlet getPost:

      logging("Method 1");
      Class clazz = Class.forName(classname);
      logging("Classloader: "+Thread.currentThread().getContextClassLoader().getClass().toString());
      logging("Method 2");
      CtClass ctclazz = classPool.get(classname);

      In response the ClassPool is throwing this exception:
      AppServer: Finding class: com.babeldoc.web.server.CountApplet
      AppServer: Method 1
      AppServer: Classloader: class org.apache.catalina.loader.WebappClassLoader
      AppServer: Method 2
      javassist.NotFoundException: com.babeldoc.web.server.CountApplet
      at javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:270)
      at javassist.ClassPoolTail.checkClassName(ClassPoolTail.java:175)
      at javassist.ClassPool.checkClassName(ClassPool.java:652)

      This is a classloader issue. The tomcat classloader is "hiding" the class from javassist. Now is there a way for me to work around this? The big problem that I have is that I dont want to write a tomcat specific fix - but rather a generic fix.

      regards and thanks in advance,
      Bruce McDonald.

        • 1. Re: Javassist and Tomcat 4.1
          chiba

          Although I cannot understand why Class.forName()
          works but classPool.get() does not (they should use
          the same class loader), let me show you some hints.

          You can explicitly tell ClassPool to load class files from
          a specific class loader. To do this,

          ClassLoader cl
          = Thread.currentThread().getContextClassLoader(); // or something else
          classPool.insertClassPath(new LoaderClassPath(cl));

          Could you see whether it works?