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

前端 未结 6 584
你的背包
你的背包 2020-12-29 14:01

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

6条回答
  •  离开以前
    2020-12-29 14:16

    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.

提交回复
热议问题