Netbeans 中的 OSGi,检索服务时出现 ClassCastException
我有一个类加载器问题。 由于我是 osgi 新手,希望答案不是那么难:)
我认为这与编译与运行时库有关。 在 Netbeans 6.7.1 项目属性中,编译时库总是传播到其他类别..所以我无法区分它们。
编译 FelixHost 时,使用下一个 jar
- Felix.jar
- osgi-core.jar
- osgi-compendium.jar
- osgi.service.obr-1.0.2.jar
但运行时,框架将加载 OBR 的实现。 该 OBR 包还包含接口定义。 我认为这就是为什么有一个 classCastException ..
我实际上希望 FelixHost 与 OBR 一起工作做一些初始的 供应..
欢迎任何想法。
im having a ClassLoader issue.
Since im quite an osgi newby, hopefully the answer isn't that hard :)
I think it has to do with Compile vs. Runtime libraries.
in Netbeans 6.7.1 project properties, the compiletime libs are always propagated to the other categories.. so i can't differentiate there.
When compiling the FelixHost the next jars are used
- Felix.jar
- osgi-core.jar
- osgi-compendium.jar
- osgi.service.obr-1.0.2.jar
But when running, the framework will load an implementation for OBR.
This OBR bundle also contains the interface definitions. I think this is why there's a classCastException..
i actually want the FelixHost to work together with OBR to do some initial
provisioning..
Any ideas are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设“FelixHost”指的是封装和启动 Felix 框架的项目。
问题是你必须要小心“OSGi 世界”和“非 OSGi 世界”之间的界限。 您放在 FelixHost 类路径上的所有内容(即您的情况下的所有编译时依赖项)本质上都位于 OSGi 世界之外,因此不建议使用像“osgi.service.obr-1.0.2.jar”这样的包这样。
正如您所指出的,如果 OSGi 框架还加载“osgi.service.obr-1.0.2.jar”包,您将陷入 ClassCastException,因为您本质上有相同类(接口)的两个版本。
此问题的一种可能的解决方案是将您的初始配置逻辑分离到一个单独的包中,并在 OSGi 世界中执行与 OBR 相关的工作。 然后,您可以删除 FelixHost 对“osgi.service.obr-1.0.2.jar”的编译依赖,并且只加载一份 OBR 接口副本。
I assume that by "FelixHost" you are referring to your project that is encapsulating and launching the Felix framework.
The problem is that you have to be a bit careful about the boundary between "OSGi world" and "non-OSGi world". Everything that you put on the classpath for FelixHost (i.e. also all compile time dependencies in your case) is essentially living outside of the OSGi world, so it's not advisable to use bundles like "osgi.service.obr-1.0.2.jar" in this way.
As you pointed out if the OSGi framework also loads the "osgi.service.obr-1.0.2.jar" bundle you will get into ClassCastException because you have essentially two versions of the same classes (interfaces).
One possible solution to this problem is to separate your initial provisioning logic into a separate bundle and do the OBR related work from within the OSGi world. Then you can remove the compile dependency of FelixHost on "osgi.service.obr-1.0.2.jar" and only have one copy of OBR interfaces loaded.