I've been looking into replacing an existing plugin system that works very well, has reasonable security and is stupid-simple to use with OSGI. The main program will not be an OSGI bundle (dont ask why, thats outside the scope of this question) There are some nifty things OSGI does like automagically install all the jars that are in a given directory and such - thats pretty neat as well as some other nifty things that again are outside the scope of this question. My question is this: Can the osgi framework (Felix in this case) exist within a bigger program that will supply some interface definitions that plugins will be required to implement depending on what they do, then be able to load them?
I've got some code working - but as you can guess I'm in class loader hell.
At run time the activator can not resolve the interfaces provided by the main application.
It seams that OSGI can* manage the exposed classes between bundles reasonable well but it doesnt play very well with things outside its control.
Could it be that OSGI is simply not worth it in this case? esp when what I have now works for the most part very well.
I tried to write a fairly small program that starts up Felix (successfully) It has its own activator that successful places itself as a service into the the root bundle. When I tried to access the service from the main program - it worked.
When I tried to create a completely separate plugin ie a different eclipse project,it installed and resolved - just like i would expect but it gives the dreaded java.lang.NoClassDefFound Error on startup.
I suspect thats because the main program is using the good old handy-dandy system class loader and friends while the other plugin that is being loaded by OSGI/Felix is being loaded by its own ClassLoader, in this case a 'good old' org.apache.felix.framework.BundleWiringImpl$BundleClassLoader. Since they are blissfully unaware of each other resolution gets 'exciting'.
It also appears that in the Manifest Export-Package only specifies what* to export, not Where to look.
Any ideas on how to make that work (with out making the main program a bundle) would be great. If not maybe some people can learn a bit from my experience.....
It appears that org.osgi.framework.system.packages.extra property in the configuration lets you expose packages from the system class loader into the system bundle and is then exposed to all the plugins.
ffi: https://felix.apache.org/documentation/subprojects/apache-felix-framework/apache-felix-framework-configuration-properties.html and https://moi.vonos.net/java/osgi-classloaders/