Package org.pf4j
Class PluginClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.pf4j.PluginClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
One instance of this class should be created by plugin manager for every available plug-in.
By default, this class loader is a Parent Last ClassLoader - it loads the classes from the plugin's jars
before delegating to the parent class loader.
Use
parentFirst
to change the loading strategy.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final org.slf4j.Logger
private boolean
private static final String
private PluginDescriptor
private PluginManager
-
Constructor Summary
ConstructorsConstructorDescriptionPluginClassLoader
(PluginManager pluginManager, PluginDescriptor pluginDescriptor, ClassLoader parent) PluginClassLoader
(PluginManager pluginManager, PluginDescriptor pluginDescriptor, ClassLoader parent, boolean parentFirst) IfparentFirst
istrue
, indicates that the parentClassLoader
should be consulted before trying to load the a class through this loader. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
getResource
(String name) Load the named resource from this plugin.getResources
(String name) Class
<?> By default, it uses a child first delegation model rather than the standard parent first.private Class
<?> loadClassFromDependencies
(String className) Methods inherited from class java.net.URLClassLoader
close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
log
private static final org.slf4j.Logger log -
JAVA_PACKAGE_PREFIX
- See Also:
-
PLUGIN_PACKAGE_PREFIX
- See Also:
-
pluginManager
-
pluginDescriptor
-
parentFirst
private boolean parentFirst
-
-
Constructor Details
-
PluginClassLoader
public PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, ClassLoader parent) -
PluginClassLoader
public PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, ClassLoader parent, boolean parentFirst) IfparentFirst
istrue
, indicates that the parentClassLoader
should be consulted before trying to load the a class through this loader.
-
-
Method Details
-
addURL
- Overrides:
addURL
in classURLClassLoader
-
addFile
-
loadClass
By default, it uses a child first delegation model rather than the standard parent first. If the requested class cannot be found in this class loader, the parent class loader will be consulted via the standardClassLoader.loadClass(String)
mechanism. UseparentFirst
to change the loading strategy.- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
getResource
Load the named resource from this plugin. By default, this implementation checks the plugin's classpath first then delegates to the parent. UseparentFirst
to change the loading strategy.- Overrides:
getResource
in classClassLoader
- Parameters:
name
- the name of the resource.- Returns:
- the URL to the resource,
null
if the resource was not found.
-
getResources
- Overrides:
getResources
in classClassLoader
- Throws:
IOException
-
loadClassFromDependencies
-