For example, with the following jar file:
/
+- foo
+- X.class
+- bar
+- X.class
ParallelWorldClassLoader("foo/") would load X.class from
/foo/X.class (note that X is defined in the root package, not
foo.X.
This can be combined with MaskingClassLoader to mask classes which are loaded by the parent
class loader so that the child class loader
classes living in different folders are loaded
before the parent class loader loads classes living the jar file publicly
visible
For example, with the following jar file:
/
+- foo
+- X.class
+- bar
+-foo
+- X.class
ParallelWorldClassLoader(MaskingClassLoader.class.getClassLoader())
would load foo.X.class from
/bar/foo.X.class not the foo.X.class
in the publicly visible place in the jar file, thus
masking the parent classLoader from loading the class from foo.X.class
(note that X is defined in the package foo, not
bar.foo.X.
| Modifier and Type | Field and Description |
|---|---|
| private final Set | |
| private final String | prefix
Strings like "prefix/", "abc/", or "" to indicate classes should be loaded normally. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | close()
Implements java. Closes this stream and releases any system resources associated with it. |
| protected Class | findClass(String name)
Overrides java. Finds the class with the specified binary name. |
| protected URL | findResource(String name)
Overrides java. Finds the resource with the given name. |
| protected Enumeration | findResources(String name)
Overrides java. Returns an enumeration of |
| public static URL |
| jars | back to summary |
|---|---|
| private final Set<JarFile> jars | |
| prefix | back to summary |
|---|---|
| private final String prefix Strings like "prefix/", "abc/", or "" to indicate classes should be loaded normally. | |
| ParallelWorldClassLoader | back to summary |
|---|---|
| public ParallelWorldClassLoader(ClassLoader parent, String prefix) | |
| close | back to summary |
|---|---|
| public synchronized void close() throws IOException Implements java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in
| |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Doc from java. Finds the class with the specified binary name.
This method should be overridden by class loader implementations that
follow the delegation model for loading classes, and will be invoked by
the
| |
| findResource | back to summary |
|---|---|
| protected URL findResource(String name) Overrides java. Doc from java. Finds the resource with the given name. Class loader implementations should override this method. For resources in named modules then the method must implement the
rules for encapsulation specified in the
| |
| findResources | back to summary |
|---|---|
| protected Enumeration Overrides java. Doc from java. Returns an enumeration of For resources in named modules then the method must implement the
rules for encapsulation specified in the
| |
| toJarUrl | back to summary |
|---|---|
| public static URL toJarUrl(URL res) throws ClassNotFoundException, MalformedURLException Given the URL inside jar, returns the URL to the jar itself.
| |