将非 osgi jar 添加到 RCP4 项目

Adding non-osgi jars to RCP4 project

我有以下情况。我依赖一个名为 foo.jar 的第三方 jar。该 jar 有许多非 osgi 依赖项。我创建了一个新项目 "Plug-in from existing JAR archives",select 编辑了所有 foo.jar 的非 osgi 依赖项并将其导出为名为 foo.libs.jar 的 "deployable plugin and fragment"。

我的 RCP4 项目是一个基于功能的产品。在我的主要 RCP 项目中,我转到目标文件,导航到“内容”选项卡并选中 foo.jar 和 foo.libs.jar。然后我转到我的项目文件和 select "validate" 并收到消息 "No problems were detected".

知道我做错了什么或需要做什么才能让它工作吗?我是否必须明确地将 foo.libs.jar 设置为 foo.jar 的依赖项?我试图在我的主要项目清单->依赖项选项卡和 runConfigurations->插件中这样做,并将 foo.libs.jar 添加到 feature.xmls-> 包含的插件选项卡,但它没有好像不行。

谢谢!

===更新===

我认为我的问题可能属于包碎片和嵌入式依赖项的情况。例如:

- I create foo.libs.jar. One of the jars inside it is activemq.jar 
  I need access to javax.jms.ExceptionListener
- The manifest for foo.libs.jar contains activemq.jar in the 
  Bundle-ClassPath, and javax.jms in the Export-Package sections
- foo.jar contains foo.libs.jar in its Class-Path. It contains  
  javax.jms in its Import-Package and Export-Package sections
- I created a "Plug-in from existing JAR archives" project which has
  foo.jar and foo.libs.jar in it.
- The manifest for the project has foo.jar and foo.libs.jar in the 
  Bundle-Classpath section. The Import-Package section contains 
  javax.jms
- If I export this bundle to my project, and run validate I get 
  errors saying javax.jms cannot be found.
- If I omit the javax.jms from the bundles Import-Package there
  are no validation errors but I will get a ClassNotFoundException

我觉得这可能是嵌入式 jar 和 Bundle-ClassPaths 的问题...

我的捆绑包有

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: my.name
Bundle-SymbolicName: my.name
Bundle-Version: 1.0.0
Bundle-ClassPath: foo.jar
Export-Package: list_of_my_packages
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

并且 foo.jar 有

Manifest-Version: 1.0
Bnd-LastModified: 1489769501680
Bundle-ManifestVersion: 2
Bundle-Name: foo
Bundle-SymbolicName: foo
Bundle-Version: 1.0.0
Class-Path: foo.libs.jar
Created-By: 1.8.0_71 (Oracle Corporation)
Export-Package: javax.jms  (and other stuff, omitted)
Import-Package: javax.jms;resolution:=optional (and other stuff, omitted)
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-2.4.0.201411031536

并且foo.libs.jar有

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Foo libs
Bundle-SymbolicName: foo.libs
Bundle-Version: 1.1.0
Bundle-ClassPath: activemq-all.jar, (and others which I ommitted)
Export-Package: javax.jms, (and others which I ommitted)
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

问题缺乏细节,但 "no class found" 的问题对于 OSGI 来说是很典型的。

检查您的两个捆绑包的 MANIFEST.MF。 foo.libs.jar 必须在 'Export-Package' 指令中为您的 "missing" class 声明一个包,而 foo.jar 必须在 'Import-Package' 中有相同的包。由于您设法达到了出现异常的程度,因此您似乎缺少 some.class.in.a.jar.in.foo.libs.jar in 'Import-Package' 的包声明foo.jar.

主要规则如下:捆绑包只能访问自身内的 classes + 通过清单导入的那些。有像包片段和嵌入式依赖项这样的例外,但我相信我们可以在这种情况下忽略它们。

通常,当您在包的清单中正确设置 'Import-' 和 'Export-Package' 指令时,问题就会得到解决。如果您需要更详细的帮助,请提供有关如何制作 foo.jar 和 foo.lib.jar 的更多详细信息(手动、通过 maven 插件、通过 gradle、您使用的设置等)