As on your request I'll post something about my little plugin framework. As I continue on the result of a university lab just for fun, there are currently some changes to expect. It supports some basic injection mechanism and code manipulation using javassist byte manipulation framework. I currently use this plugin-framework to learn and test class-loading behaviors (delegation-loading, usage of strategies to load classes, manipulate singletons to weak-singletons, ...). Next, I want to adventure into unloading of enums as they currently produce memory-leaks.
The plugin-mechanism is based on a simple interface IPlugin
found in PluginFramework/PluginInterface
which only defines a single execute()
method. Implementations of the interface can either be placed directly into the plugin-subdirectory of the base-directory or within a jar (preferred one) which has to be placed also into the plugin-subdirectory. The plugin is loaded automatically on startup of the application or on drag&dropping the jar into the plugin-directory, or on using a simplified OSGi-like load
command.
The framework itself provides a couple of actions, like list
which lists all currently loaded plugins, exec
which executes a certain plugin, load
and unload
which hopefully are self explanatory. For test-reasons there is also a gc
command to somehow force a garbage-collection (as I'm taking heapdumps to identify possible memory leaks).
Moreover, you can define a class to export or classes the plugin depends on within the MANIFEST.MF of a plugin-jar. It will only load the plugin if all dependent classes got loaded before (though it shows up in the list of available plugins if not all classes are available and the plugin therefore waits for the dependent classes). Exported classes can be further used by other plugins which require them (as described above).
What the plugin actually does, is left to the programmer of the plugin-implementation. So no security-policies yet installed. So, it is not as complex as the accepted answer of your linked post. Moreover, I'm still in a re-work (that's why I linked the unstable branch). Though, due to limited time it is not yet perfect and I'm not sure if it is already ready to be used safely within other projects - but maybe you find something you can re-use or at least find some ideas.