Package org.pf4j

Class 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. Use parentFirst to change the loading strategy.
    • 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.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • 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)
        If parentFirst is true, indicates that the parent ClassLoader 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 class java.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 standard ClassLoader.loadClass(String) mechanism. Use parentFirst to change the loading strategy.
        Overrides:
        loadClass in class java.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. Use parentFirst to change the loading strategy.
        Overrides:
        getResource in class java.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 class java.lang.ClassLoader
        Throws:
        java.io.IOException
      • loadClassFromDependencies

        private java.lang.Class<?> loadClassFromDependencies​(java.lang.String className)