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.URLClassLoaderOne 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. UseparentFirstto change the loading strategy.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringJAVA_PACKAGE_PREFIXprivate static org.slf4j.Loggerlogprivate booleanparentFirstprivate static java.lang.StringPLUGIN_PACKAGE_PREFIXprivate PluginDescriptorpluginDescriptorprivate PluginManagerpluginManager
-
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)IfparentFirstistrue, indicates that the parentClassLoadershould 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 voidaddFile(java.io.File file)voidaddURL(java.net.URL url)java.net.URLgetResource(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)
IfparentFirstistrue, indicates that the parentClassLoadershould be consulted before trying to load the a class through this loader.
-
-
Method Detail
-
addURL
public void addURL(java.net.URL url)
- Overrides:
addURLin classjava.net.URLClassLoader
-
addFile
public void addFile(java.io.File file)
-
loadClass
public java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundExceptionBy 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. UseparentFirstto change the loading strategy.- Overrides:
loadClassin 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. UseparentFirstto change the loading strategy.- Overrides:
getResourcein classjava.lang.ClassLoader- Parameters:
name- the name of the resource.- Returns:
- the URL to the resource,
nullif the resource was not found.
-
getResources
public java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOException- Overrides:
getResourcesin classjava.lang.ClassLoader- Throws:
java.io.IOException
-
loadClassFromDependencies
private java.lang.Class<?> loadClassFromDependencies(java.lang.String className)
-
-