Package org.pf4j
Class PluginClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.pf4j.PluginClassLoader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class PluginClassLoader extends java.net.URLClassLoader
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. UseparentFirst
to change the loading strategy.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
JAVA_PACKAGE_PREFIX
private static org.slf4j.Logger
log
private boolean
parentFirst
private static java.lang.String
PLUGIN_PACKAGE_PREFIX
private PluginDescriptor
pluginDescriptor
private PluginManager
pluginManager
-
Constructor Summary
Constructors Constructor Description PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, java.lang.ClassLoader parent)
PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFile(java.io.File file)
void
addURL(java.net.URL url)
java.net.URL
getResource(java.lang.String name)
Load the named resource from this plugin.java.util.Enumeration<java.net.URL>
getResources(java.lang.String name)
java.lang.Class<?>
loadClass(java.lang.String className)
By default, it uses a child first delegation model rather than the standard parent first.private java.lang.Class<?>
loadClassFromDependencies(java.lang.String className)
-
Methods inherited from class java.net.URLClassLoader
close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
-
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 Detail
-
log
private static final org.slf4j.Logger log
-
JAVA_PACKAGE_PREFIX
private static final java.lang.String JAVA_PACKAGE_PREFIX
- See Also:
- Constant Field Values
-
PLUGIN_PACKAGE_PREFIX
private static final java.lang.String PLUGIN_PACKAGE_PREFIX
- See Also:
- Constant Field Values
-
pluginManager
private PluginManager pluginManager
-
pluginDescriptor
private PluginDescriptor pluginDescriptor
-
parentFirst
private boolean parentFirst
-
-
Constructor Detail
-
PluginClassLoader
public PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, java.lang.ClassLoader parent)
-
PluginClassLoader
public PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, java.lang.ClassLoader parent, boolean parentFirst)
IfparentFirst
istrue
, indicates that the parentClassLoader
should be consulted before trying to load the a class through this loader.
-
-
Method Detail
-
addURL
public void addURL(java.net.URL url)
- Overrides:
addURL
in classjava.net.URLClassLoader
-
addFile
public void addFile(java.io.File file)
-
loadClass
public java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
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 classjava.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
-
getResource
public java.net.URL getResource(java.lang.String name)
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 classjava.lang.ClassLoader
- Parameters:
name
- the name of the resource.- Returns:
- the URL to the resource,
null
if the resource was not found.
-
getResources
public java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOException
- Overrides:
getResources
in classjava.lang.ClassLoader
- Throws:
java.io.IOException
-
loadClassFromDependencies
private java.lang.Class<?> loadClassFromDependencies(java.lang.String className)
-
-