简体   繁体   English

eclipse osgi:如何从特定包中加载类

[英]eclipse osgi: how to load class from a specific bundle

I have two bundles both active in the framework. 我在框架中都有两个捆绑包。 Each of them has its version of a set of classes under the same full name, for example, org.eclipse.jface.util.ILogger. 它们中的每一个都有一组具有相同全名的类的版本,例如org.eclipse.jface.util.ILogger。 In my code, if I write 在我的代码中,如果我写

System.out.println(ILogger.class.getClassLoader());

I can see the class loader is from one of the bundle. 我可以看到类加载器来自捆绑软件之一。 My problem is I need to use that class from the other one, not the "default" bundle picked up by the osgi framework. 我的问题是我需要使用另一个类的类,而不是osgi框架选择的“默认”包。 That is, when I write the code like 也就是说,当我编写如下代码

ILogger logger = new ILogger(){}...

I need the logger to have the type defined in the other bundle. 我需要记录器具有其他捆绑包中定义的类型。 Is there any way to do this? 有什么办法吗? I am using Eclipse 4.4. 我正在使用Eclipse 4.4。 Thanks 谢谢

After playing with it for a while, I got a way to do it. 玩了一段时间后,我有办法去做。 On the 'Dependency' tab of the manifest file, leave one bundle as the 'Required Plugins' and put the package in use from the other bundle in 'Imported Packages'. 在清单文件的“依赖关系”选项卡上,将一个捆绑软件保留为“必需的插件”,然后将另一个捆绑软件的使用软件包放入“导入的软件包”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM