未解决的要求:导入包:org.apache.commons.codec.language in bndtools/osgi

Unresolved requirement: Import-Package: org.apache.commons.codec.language in bndtools/osgi

我目前在一个项目中工作,我需要运行将 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 repo 中,我提取了一个产生错误的作为参考:https://github.com/MaPhil/osgi-externals-test

我在谷歌上搜索了很多关于这个主题的内容,但大多数答案似乎都与 liferay 或其他特定库有关。希望大家指点一下。

先说一些好消息:

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

这表明您的 OSGi 包具有 org.apache.commons.codec.language 的导入,并且它具有版本范围(1.9 到但不包括 2.0)这一事实很好地表明您的构建路径不是完全搞砸了。

查看您的示例工作区,我发现您有一个用于包装 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)"

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

您可以查看有关如何执行此类操作的更多信息in the Bndtools documentation or related details in OSGi enRoute