I have a program where I compile java code that somebody writes in a text box, and run it. They type out the full source code, class and all
I save the class they write to a random java source file, and then compile and load the class through a classloader. This works perfectly.
I have a new issue though, that of sub classes. I give the outer class a unique name, and load that class.
Ex.
TEMP1110.java -> TEMP1110.class
, etc.
With inner classes, it compiles to TEMP1110$InnerClass.class
I try loading this class through my class loader, but when the outer class makes a call to it: new InnerClass().method();
it gives me this: java.lang.NoClassDefFoundError: TEMP1110$InnerClass
Is there some quirk or something I am doing wrong?
My classloader:
private static class JClassLoader extends ClassLoader {
public Class buildClass(final byte[] data, final String className) {
return (Class) defineClass(className, data, 0, data.length);
}
}
className
being TEMPCLASS$InnerClass
, and data being the bytes that represent the class file. This works for outer classes.