1 Reply Latest reply on May 25, 2003 12:34 PM by Anatoly Akkerman

    Using Tomcat to serve classes

    triphop Newbie

      Hi all,

      I am investigating Javassist to use with babeldoc (www.babeldoc.com) in a number of roles:

      1. Gui framework
      2. Dynamic pipeline compiler.

      I am currently trying to rework the javassist.web.WebServer / Appserver to be a Tomcat 4.1 servlet. Here are the guts of the application:

      public void init() throws ServletException {
      try {
      exportedNames = new HashMap();
      exportedObjects = new ArrayList();
      classPool = ClassPool.getDefault();
      catch(Exception e) {

      And then in the doGet, called to download the classes as an octet-stream:

      public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

      logging("Path Info:"+request.getPathInfo());
      String filename = request.getPathInfo();
      byte[] classfile = null;
      String classname
      = filename.substring(1, filename.length() - 6).replace('/', '.');
      logging("Finding class: "+classname);
      try {
      logging("Method 1");
      Class clazz = Class.forName(classname);
      logging("Method 2");
      CtClass ctclass = classPool.get(classname);

      I get an exception from Javassist that it cannot load the class (that has jsut been loaded by the regular ClassLoader, or the one that Apache has provided)

      javassist.NotFoundException: com.babeldoc.web.server.Counter
      at javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:270)
      at javassist.ClassPoolTail.readClassfile(ClassPoolTail.java:234)
      at javassist.ClassPoolTail.write(ClassPoolTail.java:154)
      at javassist.ClassPoolTail.write(ClassPoolTail.java:160)

      Any and all help will be much appreciated. I am using Tomcat/4.1.24-LE-jdk14 on windows 2000.

      Bruce McDonald.

        • 1. Re: Using Tomcat to serve classes
          Anatoly Akkerman Newbie

          > Class clazz = Class.forName(classname);

          You should never use Class.forName() for dynamic classloading.
          Use Thread.currentThread.getContextClassloader().loadClass()

          Class.forName() will only load classes that are on the jvm's classpath (I think) while your context classloader should have the ability to load all the classes you need.