I use the JavaCompiler to create a class dynamical. This class implements a given interface. for the JavaCompiler I can create a correct class path so the compiler can compile my class.
//creating the classpath from parent application to be same as the runtime's
ClassLoader dummyc=getClass().getClassLoader();
URLClassLoader urlClassLoader=(URLClassLoader)dummyc;
URL[] urls=urlClassLoader.getURLs();
String classpath = "";
for (URL i : urls) {
classpath += ";" + i.getPath().substring(1);
}
I use an anonym classloader:
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = javaClassObject.getBytes();
return super.defineClass(name, javaClassObject.getBytes(), 0, b.length);
}
};
to load the compiled class but when I call the loadClass method I get this error:
NoClassDefFoundError: refac/IBewertungsAlgorithmus (wrong name: refac/MyClass)
Is it possible to set the same classpath I set for the compiler task for the class loader?