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

寵の児 提交于 2019-12-03 19:08:56

问题


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


回答1:


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.




回答2:


In OSGi 4.1 this is standardized. Have a look at http://njbartlett.name/2011/03/07/embedding-osgi.html which explains how to embed any OSGi container.




回答3:


See the project equinox-headless-service. It has code to launch equinox.




回答4:


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.




回答5:


See http://www.theserverside.com/tt/articles/article.tss?l=OSGiforBeginners




回答6:


I recently created a simple proof-of-concept of how to embed Equinox OSGi runtime in Java. For details please follow my project in Github https://github.com/sarxos/equinox-launcher



来源:https://stackoverflow.com/questions/904050/how-to-run-an-osgi-framework-within-usual-java-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!