Class PluginClassLoader

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class PluginClassLoader
    extends URLClassLoader
    ClassLoader for plugins. It searches the plugin directory for classes and JAR files, then constructs a class loader for the resources found. Resources are loaded as follows:
    • Any JAR files in the lib will be added to the classpath.
    • Any files in the classes directory will be added to the classpath.
    Author:
    Derek DeMoro
    • Constructor Detail

      • PluginClassLoader

        public PluginClassLoader()
    • Method Detail

      • addDirectory

        public void addDirectory​(File directory,
                                 boolean developmentMode)
        Adds a directory to the class loader.
        Parameters:
        directory - the directory.
        developmentMode - true if the plugin is running in development mode. This resolves classloader conflicts between the deployed plugin and development classes.
      • addURLFile

        public void addURLFile​(URL file)
        Add the given URL to the classpath for this class loader, caching the JAR file connection so it can be unloaded later
        Parameters:
        file - URL for the JAR file or directory to append to classpath
      • unloadJarFiles

        public void unloadJarFiles()
        Unload any JAR files that have been cached by this plugin