1 Reply Latest reply on Mar 30, 2006 10:50 AM by Scott Stark

    Application-specific classloading from EJB in JBoss

    Fred Wan Newbie


      I am trying to load a class with a variable name (string) from an EJB (in JBoss). In a stand-alone application the usual way of doing that is to write a custom classloader and constructing the class from a file through a bytestream if it isn't loaded. I tried to do the same thing from an EJB but that fails.

      If I try to instantiate the class like this:

      ReplyClass = (Thread.currentThread().getContextClassLoader()).loadClass(replyClassName);
      reply=(AAAReply) ReplyClass.newInstance();

      I get (for obvious reasons) this:

      16:01:17,463 INFO [STDOUT] java.lang.ClassNotFoundException: No ClassLoaders found for: AAAReplyPBAC

      If I call the classloader from the EJB like this:

      ReplyClass = ccl.loadClass(replyClassName);
      reply= (AAAReply) ReplyClass.newInstance();

      And in the classloader the class file is looked up (this is a modified version of the CompilingClassLoader from the IBM developerworks classloader tutorial)

      File classFile = new File(classFilename);
      System.out.println("classFile exists? " + classFile.exists());
      System.out.println("Path: " + classFile.getAbsolutePath());

      I get this:

      16:04:20,479 INFO [STDOUT] classFile exists? false
      16:04:20,479 INFO [STDOUT] Path: C:\jboss-4.0.3SP1\bin\AAAReplyPBAC.class
      16:04:21,682 INFO [STDOUT] general error : AAAReplyPBAC
      16:04:21,682 INFO [STDOUT] java.lang.ClassNotFoundException: AAAReplyPBAC
      16:04:21,682 INFO [STDOUT] at java.net.URLClassLoader$1.run(URLClassLoader.java:199)

      It seems that the classloader isn't looking in the right place; it should be looking in the EJB/EAR jar in the deployment directory of the application server (JBoss). Is that the case, and how can I get the classloader to look there? Or is something else wrong?