0 Replies Latest reply on Apr 12, 2006 3:08 PM by james copenhaver

    dynamically load a class from inside an EJB

    james copenhaver Newbie

      Hey All,

      My application contains a method in an EJB which does the following:
      1.) writes out a java file
      2.) compiles the java file into a class file
      3.) loads the class file dynamically

      Steps 1 and 2 work fine. Step three does not work. The error message is a "ClassNotFound" error. I did some research and found several things which helped me understand the problem in more detail. I have read, in detail, many papers which discuss the classloaders in general and explicit to JBOSS. I have read through the examples in several JBOSS text and online documentation. I currently use a URLClassLoader and the Thread.currentThread.getContext/setContext methods as my approach to define a custom classloader for the generated class with no success.

      I can run the method standalone (not in a J2EE environment) and it works fine.

      I discovered, after reading the J2EE EJB 2.0 - 3.0 specifications that there are programming restrictions in regards to the use of classloaders, which I think is where my problem exist.

      Sorry for the long winded setup, now for my questions:
      1.) Is it possible to create a class file and load it at runtime from an EJB?
      2.) If so, how would one do that?
      3.) If not, is there another approach which would solve my problem? Could you include that approach or a general outline of that approach?

      Many thanks in advance,

      Jaime