I'm trying to force the System java classloader (i.e. ClassLoader.getSystemClassLoader()
) to load an external class defined by a byte array with valid bytecode so that other classes subsequently loaded by this classloader can know about and instantiate the external class without getting a NoClassDefFoundError
.
This surely does not work as it only defines the class on the classloader created, not in the System classloader:
URLClassLoader child =
new URLClassLoader(new URL[] { myJar.toURI().toURL()
, ClassLoader.getSystemClassLoader());
Class.forName ("com.MyClass", true, child);
The code above will define com.MyClass
for the child classloader, not for the system classloader.
Any way of accomplishing that?