我正在编写一个使用 Equinox 作为我的 OSGi 框架的应用程序。我试图发现我的 bundle 注册时已知的所有 bundle 。我尝试使用以下行来检索所有可用的 bundle 。然而,
EclipseStarter.getSystemBundleContext().getBundles();
向我发出警告...
不鼓励访问:由于所需库 D:\java\eclipse\plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar 的限制,无法访问 EclipseStarter 类型的 getSystemBundleContext() 方法
获取框架内所有可用 bundle 的列表的正确用法是什么?
最佳答案
您可以在插件激活器中使用自己的捆绑上下文作为入口点,而不是 EclipseStarter:
start(BundleContext context)
{
context.getBundles(); // what you want
}
如果您不了解 Plugin
类,请查看 AbstractUIPlugin
类。
如果您确实需要单例访问,那么您的插件可能就是其中之一 - 请随意公开 YourPlugin.getInstance().getBundleContext()
。
(免责声明:我还没有尝试过 - 但它与 OSGi/Eclipse 一致)
关于java - 在 Eclipse 中获取所有包的 Bundle [],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/687405/