【问题标题】:Unresolved requirement: Import-Package: org.apache.commons.codec.language in bndtools/osgi未解决的要求:导入包:bndtools/osgi 中的 org.apache.commons.codec.language
【发布时间】:2019-04-12 06:18:07
【问题描述】:

我目前正在一个项目中工作,我需要将 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

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

【问题讨论】:

    标签: java osgi bnd bndtools


    【解决方案1】:

    一些好消息:

     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)"
    

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

    您可以查看有关如何执行此类操作的更多信息in the Bndtools documentation 或相关详细信息in OSGi enRoute

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 2017-12-23
      • 2018-05-25
      • 1970-01-01
      • 2018-08-15
      • 2018-07-21
      相关资源
      最近更新 更多