Note
this is very against the normal behavior of classloaders. Normal is to first check parent and then look in the resources you gave this classloader.
It's possible to add urls to the classpath at runtime through addURL(URL).
Why using RootLoader? If you have to load classes with multiple classloaders and a classloader does know a class which depends on a class only a child of this loader does know, then you won't be able to load the class. To load the class the child is not allowed to redirect its search for the class to the parent first. That way the child can load the class. If the child does not have all classes to do this, this fails of course.
For example:
parentLoader (has classpath: a.jar;c.jar)
|
|
childLoader (has classpath: a.jar;b.jar;c.jar)
class C (from c.jar) extends B (from b.jar)
childLoader.find("C")
--> parentLoader does know C.class, try to load it --> to load C.class it has to load B.class --> parentLoader is unable to find B.class in a.jar or c.jar --> NoClassDefFoundException!if childLoader had tried to load the class by itself, there would be no problem. Changing childLoader to be a RootLoader instance will solve that problem.
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | RootLoader(final URL[] urls, final ClassLoader parent)
Constructs a |
| public | RootLoader(final LoaderConfiguration lc)
Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public void | addURL(final URL
the URL to be added to the search path of URLs url)Overrides java. |
| protected Class | findClass(final String
the name of the class name)Overrides java. |
| public URL | getResource(final String
The resource name name)Overrides java. |
| protected synchronized Class | loadClass(final String
The binary name of the class name, final boolean If resolve)true then resolve the classOverrides java. |
| customClasses | back to summary |
|---|---|
| private final Map<String, Class<?>> customClasses | |
| ORG_W3C_DOM_NODE | back to summary |
|---|---|
| private static final String ORG_W3C_DOM_NODE | |
| RootLoader | back to summary |
|---|---|
| public RootLoader(final ClassLoader parent) Constructs a
| |
| RootLoader | back to summary |
|---|---|
| public RootLoader(final URL[] urls, final ClassLoader parent) Constructs a | |
| RootLoader | back to summary |
|---|---|
| public RootLoader(final LoaderConfiguration lc) Constructs a | |
| addURL | back to summary |
|---|---|
| public void addURL(final URL url) Overrides java. Doc from java. Appends the specified URL to the list of URLs to search for classes and resources.
If the URL specified is | |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Doc from java. Finds and loads the class with the specified name from the URL search path. Any URLs referring to JAR files are loaded and opened as needed until the class is found.
| |
| getResource | back to summary |
|---|---|
| public URL getResource(final String name) Overrides java. Doc from java. Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code. The name of a resource is a ' Resources in named modules are subject to the encapsulation rules
specified by
| |
| loadClass | back to summary |
|---|---|
| protected synchronized Class Overrides java. Doc from java. Loads the class with the specified binary name. The default implementation of this method searches for classes in the following order:
If the class was found using the above steps, and the
Subclasses of Unless overridden, this method synchronizes on the result of
| |