Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best technology for adding plugin support to a J2SE application? [closed]

I'm writing a J2SE desktop application that requires one of its components to be pluggable. I've already defined the Java interface for this plugin. The user should be able to select at runtime (via the GUI) which implementation of this interface they want to use (e.g. in an initialisation dialog). I envisage each plugin being packaged as a JAR file containing the implementing class plus any helper classes it may require.

What's the best technology for doing this type of thing in a desktop Java app?

like image 645
Andrew Swan Avatar asked Sep 17 '08 09:09

Andrew Swan


3 Answers

After many tries for plugin-based Java architectures (what is precisely what you seem to look for), I finally found JSPF to be the best solution for Java5 code. it do not have the huge needs of OSGI like solutions, but is instead rather easy to use.

like image 149
Riduidel Avatar answered Sep 28 '22 21:09

Riduidel


OSGI is certainly a valid way to go. But, assuming you dont need to unload to reload the plugin, it might be using a hammer to crack a nut.

You could use the classes in 'java.util.jar' to scan each JAR file in your plugins folder and then use a 'java.net.URLClassLoader' to load in the correct one.

like image 32
Garth Gilmour Avatar answered Sep 28 '22 23:09

Garth Gilmour


If you are "just" needing one component to be pluggable, it's enough to simply instantiate the classes based on meta information, e.g. read via a classloaders META-INF/ information from the various jars that are on your classpath or in a certain plugin directory.

OSGi on the other hand provides means to structure your whole application. If you already have a large Desktop application that needs one part pluggable, this would be a steep learning curve. If you start blank with what will be a Desktop app, OSGi provides means to modularizing the whole application. It's about "isolation of components" and independence of modules.

Apache Felix provides a nice start if you want to go down OSGi lane. It might look complicated and heavyweight, but that's only because one is not used to that level of isolation between modules. It used to be so easy to just call any public method...

like image 24
Olaf Kock Avatar answered Sep 28 '22 22:09

Olaf Kock