What it does
The Java Simple Plugin Framework was built to reduce development time while increasing code maintainability of small to medium sized projects.
- Completely hides implementation details of a component. Only use their interfaces.
- Components may be loaded with only two(!) lines of code
- Heavily annotation based: @PluginImplementation, @InjectPlugin, @Timer and @Thread, ...
- Through usage of generics it is usually type safe.
- Additional plugins to export other plugins by JavaScript, XMLRPC or ERMI. Plugins may be discovered on the local net by ZeroConf. Initial support for RDF.
(See the FAQ for more information)
(Also have a look at the Introduction-Video. Note: The video was recorded in real time, If you're a Java professional, you should skip forward manually to see the interesting parts)
What it new in this version (0.5.0-beta, May 2009)
- Two tons of bugfixes
- Service discovery works. Find exported plugins by the remote URI: discover://any or discover://nearest.
- Export your plugins to JSON (browser must support this)
- Plugins from classpath are now added by classpath://*
- Flexible options through typesafe varargs options (less API changes in the future!)
A short example
(See the Usage Guide for more information)
The following two lines demonstrate how easy it is to load existing plugins. All .JAR files inside the given directory will be examined for contained plugins which will afterwards be loaded and automatically started. No configuration files are required, nothing else has to be done.
PluginManager pm = PluginManagerFactory.createPluginManager();
pm.addPluginsFrom(new File("myPluginDir/").toURI());
// or
pm.addPluginsFrom(new File("myPluginDir/myPlugin.jar").toURI());
// or
pm.addPluginsFrom(new URI("classpath://*"));
Creating a new plugin is equally straightforward. After an interface has been designed the rest can be done by a simple annotation. The next example shows a plugin implementation that could be loaded again by JSPF, and also here: no XML- or whatsoever-files have to be created to make this work.
@PluginImplementation
public class CoolPluginImpl implements CoolPlugin {
public String provideData() {
return "I am your String";
}
}Our last two snippes indicates how plugins can be obtained from outside, and the inside of plugins. Notice the type-safety:
CoolPlugin cool = pm.getPlugin(CoolPlugin.class);
Or, from inside of plugins:
@InjectPlugin public CoolPlugin cool;
When to use it
If you are, for example, a researcher and want to quickly develop a prototype, if you intend to change implementations frequently but want to keep your code (at least partially) clean, and if you think about reusing components in other prototypes you might want to give it a try. Or if you're coding some software where you expect plugins to be loaded using some kind of easy IoC.
Known Users
- German Research Center for Artificial Intelligence (various projects)
History
This project was initially developed by Ralf Biedert. I (Nicolas Delsaux) only suggested him I could make it more sharable by putting it on code.google.com, creating a maven project, and add some little features. Thomas Lottermann contributed to various plugins.