问题描述
我正在尝试创建一个包装另一个jar的OSGi服务。我将jar添加到项目,类路径和二进制构建中。我在Activator中注册了该服务,但是当使用bundle调用该服务时,我在包装jar上获得了java.lang.NoClassDefFoundError。有谁知道我在这里做错了什么?
I am trying to create an OSGi service that wraps another jar. I added the jar to the project, the classpath and the binary build. I registered the service in the Activator but when the consuming bundle calls the service I get a java.lang.NoClassDefFoundError on the wrapper jar. Does anyone have any idea what I am doing wrong here?
提前致谢。
推荐答案
您是否正在导出使用者所需的软件包,以及实现所需的所有软件包。消费者将需要导入将被引用的所有内容。
Are you exporting the packages that are required by the consumer, as well as all those that the implementation requires. The consumer will need to import everything that will be referenced.
作为旁注,以这种方式创建包在Eclipse中用于开发并不能很好地工作(适用于运行)。如果您尝试从另一个OSGi项目引用jar中的类或接口,IDE将无法解析任何内容,因为它无法看到jar中的文件。 jar必须在bundle中展开才能看到所有内容(在IDE中)。 Eclipse基于导入和导出自动创建适当的类路径引用以用于构建目的。如果没有包中的jar文件,则必须显式维护此类路径。
As a side note, creating a bundle this way doesn't work well in Eclipse for development (works fine for runtime). If you try to reference a class or interface in the jar from another OSGi project, the IDE won't resolve anything since it cannot 'see' the files in the jar. The jar has to be expanded within the bundle for everything to be visible (within the IDE). Eclipse automagically creates the appropriate classpath references based on the imports and exports for build purposes. Without the jar file in the bundle, you will have to explicitly maintain this classpath.
这篇关于OSGi服务包装一个罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!