• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with dynamic class loading from an ejb

 
Kirk Copen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently using JBOSS 4.0.2 as my app server and ejb spec 2.1. I have a method in an ejb that writes out a java file, compiles it, and then attempts to load the class for use. I am able to compile and jar the file up with no problem, however I CANNOT figure out how to get the class loaded. I have assumed there is some kind of security restriction either in JBOSS or the EJB container that prevents me from doing this. The following code works fine in a standalone environment, but does not work when running in the ejb:

URL[] url = {new URL("jar:file:/c:/somejar.jar!/")};
URLClassLoader ucl = new URLClassLoader(url);
Thread.currentThread().setContextClassLoader(ucl);
Class thisClass = ucl.loadClass(className);

I have also tried:
Class thisClass = Class.forName(className,true,ucl);

Neither work, I have tried various approaches to get this to function properly, any help at all would be greatly appreciated, and if what I am attempting simpley cannot be done in the given framework, I just need to know so I can find an alt solution.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to be a really complicated process, I am hoping there is a reasonable justification for all of this complexity because it is certainly a solution that will quickly become very difficult to maintain. So maybe the first thing we should start with is: Why are you trying to do this? The answer will allow us to provide more meaningful input...
 
Kirk Copen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of the application is to allow front end users to dynamically create a sophisticated series of calculations. Basically allowing users to write code without having to write code. We then take all the selections made by the user to form its own java class that functions as a calculator that we can run data through. This is where we use the dynamic compile and class loading.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotcha. I definitely wouldn't have designed this solution by dynamically generating Java Code... that is way too complex and is asking for very difficult to support production issues. Depending on the complexity of these calculations it should be pretty straight-forward to implement a solution using something like the Interpreter Pattern.

If you have extremely complex calculations I would recommend taking a look at a full-blown Rules Engine like JESS... rumor is someone around these parts might even know a little bit about this subject.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!