Class ParallelWorldClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- com.sun.istack.tools.ParallelWorldClassLoader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class ParallelWorldClassLoader extends ClassLoader implements Closeable
Load classes/resources from a side folder, so that classes of the same package can live in a single jar file.For example, with the following jar file:
/ +- foo +- X.class +- bar +- X.classParallelWorldClassLoader("foo/") would loadX.classfrom/foo/X.class(note that X is defined in the root package, notfoo.X.This can be combined with
MaskingClassLoaderto 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.classParallelWorldClassLoader(MaskingClassLoader.class.getClassLoader()) would loadfoo.X.classfrom/bar/foo.X.classnot thefoo.X.classin the publicly visible place in the jar file, thus masking the parent classLoader from loading the class fromfoo.X.class(note that X is defined in the package foo, notbar.foo.X.- Author:
- Kohsuke Kawaguchi
-
-
Constructor Summary
Constructors Constructor Description ParallelWorldClassLoader(ClassLoader parent, String prefix)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected ClassfindClass(String name)protected URLfindResource(String name)protected Enumeration<URL>findResources(String name)static URLtoJarUrl(URL res)Given the URL inside jar, returns the URL to the jar itself.-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
ParallelWorldClassLoader
public ParallelWorldClassLoader(ClassLoader parent, String prefix)
-
-
Method Detail
-
findClass
protected Class findClass(String name) throws ClassNotFoundException
- Overrides:
findClassin classClassLoader- Throws:
ClassNotFoundException
-
findResource
protected URL findResource(String name)
- Overrides:
findResourcein classClassLoader
-
findResources
protected Enumeration<URL> findResources(String name) throws IOException
- Overrides:
findResourcesin classClassLoader- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
toJarUrl
public static URL toJarUrl(URL res) throws ClassNotFoundException, MalformedURLException
Given the URL inside jar, returns the URL to the jar itself.- Parameters:
res- Resource in a jar- Returns:
- URL to the conaining jar file
- Throws:
ClassNotFoundException- if res does not denote jar URLMalformedURLException- if computed URL is invalid
-
-