I am using JavaCompiler to compile CustomProcessor.java from within a web application at runtime
package com.notmycompany;
import com.mycompany.Processor;
import com.mycompany.Event;
public class CustomProcessor extends Processor {
@Override
public void process( Event evt) {
// Do you own stuff
System.out.println( "My Own Stuff");
}
}
Compilation goes well, I end up with a class file that I am trying to load using URLClassLoader
URL[] urls = new URL[]{ new URL("file://d:/temp/") };
URLClassLoader ucl = new URLClassLoader(urls);
Class clazz = ucl.loadClass("com.notmycompany.CustomProcessor");
The problem is I am hitting a ClassNotFoundException
on Processor
which I am using elsewhere in the application (as in I known it's there).
What do I need to do so com.mycompany.Processor
is visible at runtime?
Caused by: java.lang.ClassNotFoundException: com.mycompany.Processor
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 more
Thanks.
It is a matter of using a URLClassLoader
fed with a complete classpath
As per this question I used
URLClassLoader ucl2 = new URLClassLoader( new URL[] { new URL( "file://d:/temp/")}, urlClassLoader);
Class<?> clazz = ucl2.loadClass("com.notmycompany.CustomProcessor");