Hi,
I am facing problems while loading dynamically classes in my servlet. For my
application's purposes, I have to generate java code and compile it on the fly, then
use it.
Using standard reflexion mecanisms, I try to instanciate a new testClass object. If it
fails, I fork a new process to generate the class, and retry to instanciate this
object again.
If testClass.class is not present when I'm starting Tomcat 4.0b6, there is no way i
can instanciate a testClass Object. (exceptions are raised in both blocks)
If I put testClass.class in the CLASSPATH, after starting Tomcat 4.0b6, then I can
instanciate a testClass Object (no exception raised in the first block, second block
not reached)
If I comment out the first block (I always generate the testClass.class file), then
everything works fine, but this is unacceptable.
I also tried using classLoader, but failed again.
Don't know if it really is Tomcat related. Any clues ?
Thanks for the help !
Regards,
/Frank
public class LoadClassSample extends HttpServlet {
...
try {
Class testObjClass = Class.forName("testClass");
Object testObject = testObjClass.newInstance();
} catch( ClassNotFoundException CNFException ) {
try {
Process _proc = Runtime.getRuntime().exec("/usr/lib/java/bin/javac
/tmp/testClass.java -d
/usr/local/jakarta-tomcat-4.0-b6/webapps/examples/WEB-INF/classes/");
_proc.waitFor();
Class testObjClass = Class.forName("testClass");
Object testObject = testObjClass.newInstance();
...
} catch( Exception PROCException ) {
...
}
...