首页 > 解决方案 > 未解决的要求:导入包:bndtools/osgi 中的 org.apache.commons.codec.language

问题描述

我目前正在一个项目中工作,我需要将 PDE 样式插件转移到 bnd 样式插件。我遇到了外部 jar 的问题,所以我为每个 jar 构建捆绑包并将它们包含到构建路径中。对于大多数罐子来说,这都很好,但我得到了一个不符合预期的罐子。

org.apache.commons.codec.language。这个包来自 jar org.apache.commons.codec,它解析得很好(至少对于 bndtools)但是当我运行这个包时,我得到了以下错误:

! could not resolve the bundles: [test-0.0.0 org.osgi.framework.BundleException: Could not resolve module: test [1]
  Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"

]
! Failed to start bundle test-0.0.0, exception Could not resolve module: test [1]
  Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"

org.osgi.framework.BundleException: Could not resolve module: test [1]
  Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"

    at org.eclipse.osgi.container.Module.start(Module.java:447)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:431)
    at aQute.launcher.Launcher.startBundles(Launcher.java:519)
    at aQute.launcher.Launcher.activate(Launcher.java:425)
    at aQute.launcher.Launcher.run(Launcher.java:303)
    at aQute.launcher.Launcher.main(Launcher.java:149)

在这个 github 存储库中,我提取了一个会产生错误的作为参考:https ://github.com/MaPhil/osgi-externals-test

我在谷歌上搜索了很多关于这个主题的信息,但大多数答案似乎都围绕着 liferay 或其他特定库。我希望你们中的任何人都可以给我一个提示。

标签: javaosgibndbndtools

解决方案


一些好消息开始:

 Unresolved requirement: Import-Package: org.apache.commons.codec.language; version="[1.9.0,2.0.0)"

这表明您的 OSGi 捆绑包有一个org.apache.commons.codec.language.

查看您的示例工作区,我看到您有一个项目用于包装 Apache Commons Codec 库。我对您为什么要这样做感到有些困惑,因为 Apache Commons Codec 已经作为 OSGi 捆绑包提供。如果您想在工作区中依赖它,只需将其添加到现有存储库之一即可。例如,/cnf/central.maven您可以添加:

commons-codec:commons-codec:1.9

这将引用 Maven Central 的官方版本。然后,您可以使用以下命令在 bnd 文件的构建路径中引用此捆绑包:

-buildpath: org.apache.commons.codec

要运行您的应用程序,您实际上应该创建一个bndrun文件,您可以使用它来声明您的需求(在这种情况下是您的测试项目的需求),然后使用一个Resolve操作(Bndtools 中的按钮或 Gradle 任务)。这将获取您的列表-runrequirements并创建一个-runbundles. 它最终会看起来像这样:

-runrequirements: osgi.identity;filter:='(osgi.identity=test)'

-runfw: org.eclipse.osgi;version='[3.13.100.v20180827-1536,3.13.100.v20180827-1536]'

-runbundles: test;version="[0.0.0,0.0.1)",\
     org.apache.commons.codec;version="[1.9.0,1.9.1)"

然后,您可以直接从该 bndrun 文件运行。它将启动框架并为您部署所有运行包。如果您使用 Bndtools,那么它甚至可以使部署的包与您的 Eclipse 工作区保持同步,以便您始终部署最新的代码。

您可以在 Bndtools 文档OSGi enRoute 中的相关详细信息中查看有关如何执行此类操作的更多信息


推荐阅读