public class ExtendedURLClassLoader
extends java.net.URLClassLoader
URLClassLoader
to provide just minimal set of modifications.
Either way, you can specify wildcard rules to force some behavior - like loading some package/class exclusively with specific loader. There are the following groups:
The order of matching is also set by loading strategy. For parent-first strategy, loader group rules will be checked first. For parent-last strategy, parent group rules will be checked first.
By default, the list of parent-only group is populated with
JavaInfo.getJrePackages()
JRE packages}.
When parent-last strategy is used, be aware how you use
ClassLoaderUtil
as it is designed to follow parent-first
strategy. Use with caution as setting parent-last violates the
class loader hierarchy.
Modifier and Type | Class and Description |
---|---|
protected static class |
ExtendedURLClassLoader.Loading |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
loaderOnlyRules |
protected boolean |
matchResourcesAsPackages |
protected java.lang.ClassLoader |
parentClassLoader |
protected boolean |
parentFirst |
protected java.lang.String[] |
parentOnlyRules |
Constructor and Description |
---|
ExtendedURLClassLoader(java.net.URL[] classpath,
java.lang.ClassLoader parent,
boolean parentFirst) |
ExtendedURLClassLoader(java.net.URL[] classpath,
java.lang.ClassLoader parent,
boolean parentFirst,
boolean excludeJrePackagesFromLoader)
Creates class loader with given loading strategy.
|
Modifier and Type | Method and Description |
---|---|
void |
addLoaderOnlyRules(java.lang.String... packages)
Adds loader-only rules for classes which must be loaded using this
loader.
|
void |
addParentOnlyRules(java.lang.String... packages)
Adds parent only rules for classes which must be loaded on the
parent loader.
|
java.net.URL |
getResource(java.lang.String resourceName)
Returns a resource using parent-first or parent-last strategy.
|
java.util.Enumeration<java.net.URL> |
getResources(java.lang.String resourceName) |
protected boolean |
isMatchingRules(java.lang.String name,
java.lang.String... rules)
Returns
true if class or resource name matches
at least one package rule from the list. |
protected java.lang.Class<?> |
loadClass(java.lang.String className,
boolean resolve)
Loads class using parent-first or parent-last strategy.
|
protected ExtendedURLClassLoader.Loading |
resolveLoading(boolean parentFirstStrategy,
java.lang.String className)
Resolves loading rules.
|
protected ExtendedURLClassLoader.Loading |
resolveResourceLoading(boolean parentFirstStrategy,
java.lang.String resourceName)
Resolves resources.
|
void |
setMatchResourcesAsPackages(boolean matchResourcesAsPackages)
When set, resources will be matched in the same way as packages.
|
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
protected final java.lang.ClassLoader parentClassLoader
protected java.lang.String[] parentOnlyRules
protected java.lang.String[] loaderOnlyRules
protected final boolean parentFirst
protected boolean matchResourcesAsPackages
public ExtendedURLClassLoader(java.net.URL[] classpath, java.lang.ClassLoader parent, boolean parentFirst)
public ExtendedURLClassLoader(java.net.URL[] classpath, java.lang.ClassLoader parent, boolean parentFirst, boolean excludeJrePackagesFromLoader)
public void addParentOnlyRules(java.lang.String... packages)
public void addLoaderOnlyRules(java.lang.String... packages)
public void setMatchResourcesAsPackages(boolean matchResourcesAsPackages)
protected boolean isMatchingRules(java.lang.String name, java.lang.String... rules)
true
if class or resource name matches
at least one package rule from the list.protected ExtendedURLClassLoader.Loading resolveLoading(boolean parentFirstStrategy, java.lang.String className)
protected ExtendedURLClassLoader.Loading resolveResourceLoading(boolean parentFirstStrategy, java.lang.String resourceName)
protected java.lang.Class<?> loadClass(java.lang.String className, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
public java.net.URL getResource(java.lang.String resourceName)
getResource
in class java.lang.ClassLoader
public java.util.Enumeration<java.net.URL> getResources(java.lang.String resourceName) throws java.io.IOException
getResources
in class java.lang.ClassLoader
java.io.IOException
Copyright © 2003-present Jodd Team