I'd like to implement a dynamic plugin feature in a Java application. Ideally:
- The application would define an interface
Plugin
with a method likegetCapabilities()
. - A plugin would be a JAR
pluginX.jar
containing a classPluginXImpl
implementingPlugin
(and maybe some others). - The user would put
pluginX.jar
in a special directory or set a configuration parameter pointing to it. The user should not necessarily have to includepluginX.jar
in their classpath. - The application would find
PluginXImpl
(maybe via the JAR manifest, maybe by reflection) and add it to a registry. - The client could get an instance of
PluginXImpl
, e.g., by invoking a method likegetPluginWithCapabilities("X")
. The user should not necessarily have to know the name of the plugin.
I've got a sense I should be able to do this with peaberry, but I can't make any sense of the documentation. I've invested some time in learning Guice, so my preferred answer would not be "use Spring Dynamic Modules."
Can anybody give me a simple idea of how to go about doing this using Guice/peaberry, OSGi, or just plain Java?