如何检测是否在osgi容器中运行 [英] how to detect if running in osgi container

查看:143
本文介绍了如何检测是否在osgi容器中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OSGi包,也可以在纯Java进程中运行。我需要能够判断该软件包是否已加载到OSGi系统中。我怎样才能做到这一点?如果没有OSGi标准的方法,我将解决Eclipse / Equinox特定的方法。

解决方案

如果你没有激活器,您也可以尝试询问您的捆绑包:

  Bundle b = org.osgi.framework.FrameworkUtil .getBundle(MyClass.this); 

如果它返回null,你的类没有被OSGi加载。


I have an OSGi bundle that can also run in plain Java process. I need to be able to tell if the bundle was loaded in an OSGi system or not. How can I do that? If there is no OSGi-standard way of doing this, I will settle for Eclipse/Equinox-specific approach.

解决方案

If you don't have an activator, you can also try asking for your bundle:

Bundle b = org.osgi.framework.FrameworkUtil.getBundle(MyClass.this);

If it returns null, your class wasn't loaded by OSGi.

这篇关于如何检测是否在osgi容器中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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