Showing 6 results.
Items per Page 50
of 1

CVP Forum

« Back to General Discussion

How to dynamically load application class from common class?

Combination View Flat View Tree View
Threads [ Previous | Next ]
In mimicing Audium generic Decision and Aciton elements, we tried to implement a feature where a generic ExpressWare Action element can be configured (through a setting) to load an application-specific business logic object.

The fully qualified classname of the object is specified as a setting, and at execution time, the Action element uses Class.forName() to instantiate the business object.

Right now we get a ClassNotFoundException and the only way to get it to work is to move the application-specific business logic class to common/lib directory. As the number of application grows these classes will become unmanageable.

Is there any trick in Audium that can make this work? Cause on the surface Audium decision element (using Java class) works in a very similar way.

Thanks!

Chin,

I've discussed this with our engineers here and thre is a way you can do this without having to change the location of the JAR or class files. Basically, you use a URL classloader to add to the current classloader and load the class that way. Basically you do the following:

1) Create a new URL object that points to the directory in which the classes you wish to load reside. You will know the name of the application, so you can put together the URL. Since you are loading a file and not accessing a URL, use the "file" protocol contructors. You can make the URL point to the java/classes directory and make another pointing to the java/lib directory or individual JAR files within it. Now, you can additionally refer to the AUDIUM_HOME environment variable to determine the path so you don't have the path hardcoded.

2) Create a new URLClassLoader object with the URLs you created.

3) Use the loadClass method of URLClassLoader to load the class.

This process is very much like the process we use in our classloaders.

Hope this helps!

Hi,

I implemented the URLClassLoader and it seems to work. Thanks!