Java 未解决的需求:导入包:bndtools/osgi中的org.apache.commons.codec.language
我目前正在一个项目中工作,我需要将PDE风格的插件转换为bnd风格的插件。 我遇到了外部jar的问题,所以我为每个jar构建了bundle,并将它们包含到构建路径中。对于大多数罐子来说,这很好,但我得到了一个不符合预期的 org.apache.commons.codec.language。这个包来自jar org.apache.commons.codec,它可以很好地解析(至少对于bndtools是这样),但是当我运行这个包时,会出现以下错误:Java 未解决的需求:导入包:bndtools/osgi中的org.apache.commons.codec.language,java,osgi,bnd,bndtools,Java,Osgi,Bnd,Bndtools,我目前正在一个项目中工作,我需要将PDE风格的插件转换为bnd风格的插件。 我遇到了外部jar的问题,所以我为每个jar构建了bundle,并将它们包含到构建路径中。对于大多数罐子来说,这很好,但我得到了一个不符合预期的 org.apache.commons.codec.language。这个包来自jar org.apache.commons.codec,它可以很好地解析(至少对于bndtools是这样),但是当我运行这个包时,会出现以下错误: ! could not resolve the b
! 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中,我提取了一个产生错误的引用:
我在谷歌上搜索了很多关于这个话题的内容,但大多数答案似乎都是关于liferay或其他特定的库。我希望你们中的任何人都能给我一个提示。首先是一些好消息: 这表明您的OSGi捆绑包有一个针对
org.apache.commons.codec.language
的导入,并且它有一个版本范围(1.9到但不包括2.0)这一事实很好地表明您的构建路径没有完全混乱
看看您的示例工作区,我看到您有一个项目,用于包装Apache Commons编解码器库。我有点不明白为什么要这样做,因为ApacheCommons编解码器已经作为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文件运行。它将启动框架并为您部署所有runbundle。如果您使用Bndtools,那么它甚至会使部署的bundle与您的Eclipse工作区保持同步,以便您始终部署最新的代码
您可以查看有关如何执行此类操作的更多信息或相关详细信息
-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)"