(Terrible Title, I know)
The best way to explain this, is that I need to load some classes that will be loaded at Runtime from a URLClassLoader, by these classes have references to instances of classes that are already loaded by the System ClassLoader and they can’t be reloaded because of some other issues.
Also, I am willing to change around my code so I can load classes from a jar in the class path with the System ClassLoader, but I haven’t been able to do that.
No. Every classloader has the bootstrap classloader as an ancestor, and trying to load a class that is already defined in a classloader will just result in use of the ancestor’s version. This is intentional to prevent
java.lang.Objectand other intrinsics from being redefined.From the javadoc for
ClassLoader:You may be able to define a custom classloader that exposes
defineClasswithout it being called byfindClassand avoid the delegation that happens infindClass, but I would not rely ondefineClass(className, bytes)working as intended on all JVMs whenparent.findClass(className)exists.