I use Equinox, the Eclipse OSGi implementation.
* Launch the OSGi framework.
* @param installArea Directory path to where the OSGi bundles remain.
* @param configArea Direcotory path to where OSGi should store its configuration data.
public void launchOsgi( String installArea, String configArea )
System.setProperty( "osgi.install.area", installArea );
System.setProperty( "osgi.configuration.area", configArea );
FrameworkAdaptor adaptor = new BaseAdaptor( null );
OSGi osgiInstance = new OSGi( adaptor );
The installation area points to a location in the file system where you want to make your OSGi runtime believe it is "installed", i.e. where it would look for bundles if you used the
The config area points to the location where you want your OSGi runtime to store configuration information about bundles you install while it is running. As you probably know, OSGi stores information about every bundle you install such that upon the next restart, you will not have to install all bundles from scratch again.
Instead of setting system properties, which is admittedly a bit cumbersome, you could pass parameters to the
BaseAdaptorconstructor, but I havent figured out the parameter names yet :-)
From the OSGi instance you have created you can use
osgiInstance.getBundleContext()to install and manage bundles.
That's basically all you need to build an OSGi-based plugin mechanism into your application.
Well, almost. Of course you will need to write some code to detect new bundles in the install area or other locations (at start time of your application or dynamically at runtime of your application). You could use functionality like Peter Kriens' FileInstall bundle, for example. Equinox has something similar but I have not looked at it yet :-)
I might cover this topic in one of my future posts.