Hi there!
Can anybody give me an example how to use the osgi framework classes? I haven't a clue how to use those classes ...
BR,
Markus
Hi there!
Can anybody give me an example how to use the osgi framework classes? I haven't a clue how to use those classes ...
BR,
Markus
The specification does not define how to instantiate, configure and start an OSGi framework. Therefore running OSGi framework from your usual Java code is always specific for the given framework implementation (Equinox, Felix, Knopplerfish,...).
It's reasonably easy to embed Apache Felix (an open-source OSGi framework) into your application.
See http://felix.apache.org/site/launching-and-embedding-apache-felix.html for more information.
See the project equinox-headless-service. It has code to launch equinox.
It dependes on which OSGi implementation you are using. I use Eclipse Equinox and start the framework from within a regular java class. The Eclipse jar (called org.eclipse.osgi_longversion.jar) has a class called org.eclipse.core.runtime.adaptor.EclipseStarter. This will boot your OSGi framework.
Properties props = new Properties();
// add some properties to config the framework
EclipseStarter.setInitialProperties(props);
BundleContext context = EclipseStarter.startup(new String[]{},null);
You need some properties to configure the framework. You can see all the documented properties here. Once you call startup, the BundleContext you receive is the System Bundle context, so you can install/start/stop bundles from here.
If you set all the properties, you won't have to pass any arguments to startup().
You can download all Equinox and other bundles from the Equinox website.