如何将 cglib 添加到 RCP 客户端的 OSGI 清单中?

How to add cglib to a OSGI manifest of RCP client?

我想使用 cglib in an RCP client. The RCP client is build using maven and the tycho plugin。我们正在使用清单优先策略。

这是我的 MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: INFO+ RCP Common UI Plug-in
Bundle-SymbolicName: a.company.prj.rcp.common.ui
Bundle-Version: 8.0.14.qualifier
Bundle-Vendor: Schweizerische Bundesbahnen SBB
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Activator: a.company.prj.rcp.common.ui.CommonUIPlugin
Bundle-ActivationPolicy: lazy
Export-Package: 
 a.company.prj.rcp.common.ui,
 ...
 a.company.prj.rcp.common.ui.wizards.page
Import-Package: 
 org.apache.log4j;version="1.2.17"
Require-Bundle: 
 org.eclipse.ui;bundle-version="3.7.0",
 org.eclipse.ui.forms;bundle-version="3.5.101",
 com.ibm.ws.jpa.thinclient;bundle-version="8.0.6",
 ...
 a.company.prj.rcp.core;bundle-version="8.0.14",
 ...

为了添加 cglib,我将 Import-Package 部分更改为:

Import-Package: 
 net.sf.cglib;version="3.2.0",
 org.apache.log4j;version="1.2.17"

现在 Eclipse 抱怨:

No available bundle exports package 'net.sf.cglib'

Ayn 有想法如何将 cglib 包含在此环境中?

您需要将 cglib 包添加到您的目标平台,即 Tycho 在解析依赖项时将考虑的所有包的集合。您有三种选择(摘自关于此主题的 Tycho wiki page):

  1. 你可以简单地 add an entire p2 repository to your target platform.
  2. 你可以use a .target file and reference the cglib bundle therein (as already suggested by stempler).
  3. 你可以 declare a Maven <dependency>cglib 上让第谷“考虑”它。

由于您已经有了一个可用的 Tycho 构建,我建议您使用您或您的同事之前在构建中使用过的任何选项。

还有一点要注意:选项 1 和 2 要求 cglib 包在 p2 存储库中可用,而选项 3 即使包来自“普通”Maven 存储库,如 [=23] =].但是在所有这三种情况下,cglib JAR 必须 是一个有效的 OSGi 包,即包含一个 OSGi MANIFEST.MFBundle-SymbolicName

您应该先将 cglib jar 文件构建为插件并将其安装在 Eclipse 中,然后才能使用它。你可以参考这个link:How can I add the external jar to the eclipse rcp application?