Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run an OSGi framework within usual java-code?

Tags:

java

osgi

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

like image 707
Markus Avatar asked May 24 '09 16:05

Markus


1 Answers

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.

like image 53
omerkudat Avatar answered Oct 26 '22 11:10

omerkudat