如何在通常的java代码中运行OSGi框架? [英] How to run an OSGi framework within usual java-code?

查看:136
本文介绍了如何在通常的java代码中运行OSGi框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能举例说明如何使用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

推荐答案

它依赖于您正在使用的OSGi实现。我使用Eclipse Equinox并从常规java类中启动框架。 Eclipse jar(名为org.eclipse.osgi_longversion.jar)有一个名为org.eclipse.core.runtime.adaptor.EclipseStarter的类。这将启动您的OSGi框架。

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);

您需要一些属性来配置框架。您可以看到所有记录的属性这里。一旦你调用startup,你收到的BundleContext就是System Bundle上下文,所以你可以从这里安装/启动/停止bundle。

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.

如果设置了所有的属性,你就可以了不必将任何参数传递给startup()。

If you set all the properties, you won't have to pass any arguments to startup().

你可以从 Equinox网站

这篇关于如何在通常的java代码中运行OSGi框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆