Class ClassLoaderPluginLoader
java.lang.Object
com.fathzer.plugin.loader.PluginLoader<ClassLoader>
com.fathzer.plugin.loader.classloader.ClassLoaderPluginLoader
A class able to load plugins from jar files contained in a folder.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ClassLoaderbuildClassLoader(ClassLoader context) Builds the classloader that will be used to load the plugin classes.<V> List<V>getPlugins(Class<V> aClass) Loads plugins using thecontext ClassLoaderof the calling thread.<V> List<V>getPlugins(ClassLoader source, Class<V> aClass) Gets the plugins contained in a source.Methods inherited from class com.fathzer.plugin.loader.PluginLoader
withClassNameBuilder, withExceptionConsumer, withInstanceBuilder
-
Constructor Details
-
ClassLoaderPluginLoader
public ClassLoaderPluginLoader()Constructor.
By default, the class name of the plugins are searched with aServiceClassNameBuilder.
The plugins are instantiated using their public no argument constructor.
This makes the default behaviour quite similar toServiceLoader
-
-
Method Details
-
getPlugins
Loads plugins using thecontext ClassLoaderof the calling thread.- Type Parameters:
V- The plugins type- Parameters:
aClass- The interface/class implemented/sub-classed by the plugins- Returns:
- A List of instances whose class loader is the classLoader returned by
PluginLoader.buildClassLoader(Object). - Throws:
IOException- if a problem occurs while reading the source.PluginInstantiationException- if a problem occurs while creating the plugins.- See Also:
-
getPlugins
Gets the plugins contained in a source. If that source is null, then thecontext ClassLoaderof the calling thread is used.- Overrides:
getPluginsin classPluginLoader<ClassLoader>- Type Parameters:
V- The interface/class of the plugins (all plugins should implement/extends this interface/class).- Parameters:
source- The source to scan.aClass- The interface/class implemented/sub-classed by the plugins- Returns:
- A list of instances whose class loader is the classLoader returned by
PluginLoader.buildClassLoader(Object). - Throws:
IOException- if a problem occurs while reading the source.
-
buildClassLoader
Description copied from class:PluginLoaderBuilds the classloader that will be used to load the plugin classes.- Specified by:
buildClassLoaderin classPluginLoader<ClassLoader>- Parameters:
context- The context, for example, the path of a jar file.- Returns:
- A classLoader that can load classes from the context.
-