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 Stringprivate static final org.slf4j.Loggerprivate booleanprivate static final Stringprivate PluginDescriptorprivate PluginManager -
Constructor Summary
ConstructorsConstructorDescriptionPluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, ClassLoader parent) PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, ClassLoader parent, boolean parentFirst) IfparentFirstistrue, indicates that the parentClassLoadershould be consulted before trying to load the a class through this loader. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidgetResource(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 URLClassLoader
close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstanceMethods inherited from class SecureClassLoader
defineClass, defineClassMethods inherited from class 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) IfparentFirstistrue, indicates that the parentClassLoadershould be consulted before trying to load the a class through this loader.
-
-
Method Details
-
addURL
- Overrides:
addURLin 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. UseparentFirstto change the loading strategy.- Overrides:
loadClassin 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. UseparentFirstto change the loading strategy.- Overrides:
getResourcein classClassLoader- Parameters:
name- the name of the resource.- Returns:
- the URL to the resource,
nullif the resource was not found.
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
loadClassFromDependencies
-