public class ParallelWorldClassLoader
extends java.lang.ClassLoader
implements java.io.Closeable
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 java.util.Set<java.util.jar.JarFile> |
jars |
private java.lang.String |
prefix
Strings like "prefix/", "abc/", or "" to indicate
classes should be loaded normally.
|
Constructor and Description |
---|
ParallelWorldClassLoader(java.lang.ClassLoader parent,
java.lang.String prefix) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected java.lang.Class |
findClass(java.lang.String name) |
protected java.net.URL |
findResource(java.lang.String name) |
protected java.util.Enumeration<java.net.URL> |
findResources(java.lang.String name) |
static java.net.URL |
toJarUrl(java.net.URL res)
Given the URL inside jar, returns the URL to the jar itself.
|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
private final java.lang.String prefix
private final java.util.Set<java.util.jar.JarFile> jars
public ParallelWorldClassLoader(java.lang.ClassLoader parent, java.lang.String prefix)
protected java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
findClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
protected java.net.URL findResource(java.lang.String name)
findResource
in class java.lang.ClassLoader
protected java.util.Enumeration<java.net.URL> findResources(java.lang.String name) throws java.io.IOException
findResources
in class java.lang.ClassLoader
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public static java.net.URL toJarUrl(java.net.URL res) throws java.lang.ClassNotFoundException, java.net.MalformedURLException
java.lang.ClassNotFoundException
java.net.MalformedURLException