public class MultipleParentClassLoader extends ClassLoader
This ClassLoader is capable of loading classes from multiple parents. This class loader
implicitly defines the bootstrap class loader to be its direct parent as it is required for all class loaders.
This can be useful when creating a type that inherits a super type and interfaces that are defined by different,
non-compatible class loaders.
Note: Instances of this class loader can have the same class loader as its parent multiple times,
either directly or indirectly by multiple parents sharing a common parent class loader. By definition,
this implies that the bootstrap class loader is #(direct parents) + 1 times a parent of this class loader.
For the ClassLoader.getResources(java.lang.String) method, this means that this class loader
might return the same url multiple times by representing the same class loader multiple times.
Important: This class loader does not support the location of packages from its multiple parents. This breaks package equality when loading classes by either loading them directly via this class loader (e.g. by subclassing) or by loading classes with child class loaders of this class loader.
| Modifier and Type | Class and Description |
|---|---|
static class |
MultipleParentClassLoader.Builder
A builder to collect class loader and that creates a
MultipleParentClassLoader only if multiple or no
ClassLoaders are found in the process. |
protected static class |
MultipleParentClassLoader.CompoundEnumeration
A compound URL enumeration.
|
| Constructor and Description |
|---|
MultipleParentClassLoader(List<? extends ClassLoader> parents)
Creates a new class loader with multiple parents.
|
| Modifier and Type | Method and Description |
|---|---|
URL |
getResource(String name) |
Enumeration<URL> |
getResources(String name) |
Class<?> |
loadClass(String name) |
String |
toString() |
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResourceAsStream, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignerspublic MultipleParentClassLoader(List<? extends ClassLoader> parents)
parents - The parents of this class loader in their application order.public Class<?> loadClass(String name) throws ClassNotFoundException
loadClass in class ClassLoaderClassNotFoundExceptionpublic URL getResource(String name)
getResource in class ClassLoaderpublic Enumeration<URL> getResources(String name) throws IOException
getResources in class ClassLoaderIOExceptionCopyright © 2014–2015. All rights reserved.