I am trying to deploy a dynamic web project in a way that allows me to dynamically add Quartz jobs to the classpath. Here is my thinking.
'If I read configuration from an XML file containing a fully qualified classpath, then use Class.forName() in the class to create an instance of said class from the config XML, then I should be able to access dynamically added classes placed in Tomcats TOMCAT_HOME/lib directory'.
Before this update, the application worked fine, but I had these newly externalized classes contained in the war. However, I can no longer do this because I:
However, I am getting a NoClassDefFoundError when I run the class.forName() method. I have already verified in catalina.properties that the lib directory in Tomcat is in the common.loader property.
My question is, how can I get my WAR classes to recognize the classes in a jar in the Tomcat common library. Any ideas? Thanks.
addition:
@BalusC: I have actually already developed a web based admin screen which allows the user to edit the XML config file to add new jobs. However, to add not just another instance of a job, but an entirely new job, there needs to be code definition of this new job. I want that to be placed into a jar file to be dropped into the tomcat lib directory to be picked up by class.forName().
Hopefully, Tomcat does not reload automatically your context or loads the jars in your classloader automatically. It could result in uncontrollable behaviors.
You will never be able to access those new classes in the WebAppClassLoader
(the one managed per tomcat context) without loading the explicitly the jar through an URLClassLoader
. I'll advice to use an absolute path to the jar. For some dark reasons I had issues with relative path.
If you want to know the tomcat installation path and for instance the lib directory, you could use the catalina.home
and catalina.base
environment variables.
HIH
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.