BndTools,如何添加非OSGi JAR?

时间:2018-04-12 08:56:51

标签: maven osgi maven-plugin bnd bndtools

BndTools,如何添加非OSGi JAR?我想将 jcraft 库添加到我的osgi项目中。使用普通JAR会破坏整个项目。缺少要求布线包

ERROR: Bundle com.herle.iiot.application.installation [6] Error starting file:/D:/HERLE/Data/iot-sdk/FelixLauncher/bundle/com.herle.iiot.application.installation-1.5.0.jar
(org.osgi.framework.BundleException: Unable to resolve com.herle.iiot.application.installation [6](R 6.0): missing requirement [com.herle.iiot.application.installation [6](R 6.0)] osgi.w
iring.package; (osgi.wiring.package=com.jcraft.jzlib) Unresolved requirements: [[com.herle.iiot.application.installation [6](R 6.0)] osgi.wiring.package; (osgi.wiring.package=com.jcraft.jzlib)]
)
org.osgi.framework.BundleException: Unable to resolve com.herle.iiot.application.installation [6](R 6.0): missing requirement [com.herle.iiot.application.installation [6](R 6.0)] osgi.wi
ring.package; (osgi.wiring.package=com.jcraft.jzlib) Unresolved requirements: [[com.herle.iiot.application.installation [6](R 6.0)] osgi.wiring.package; (osgi.wiring.package=com.jcraft.jzlib)]
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
        at java.lang.Thread.run(Unknown Source)
[Device Manager] info: Passive start
Watched path D:\HERLE\Data\iot-sdk\FelixLauncher\fileinstall key sun.nio.fs.WindowsWatchService$WindowsWatchKey@ae7c53
{felix.fileinstall.poll (ms) = 2000, felix.fileinstall.dir = D:\HERLE\Data\iot-sdk\FelixLauncher\.\fileinstall, felix.fileinstall.log.level = 4, felix.fileinstall.bundles.new.start = tru
e, felix.fileinstall.tmpdir = .\tmp, felix.fileinstall.filter = null, felix.fileinstall.start.level = 0}

请告诉我如何使用bnd.bnd配置文件执行此操作?

1 个答案:

答案 0 :(得分:4)

要考虑的主要是配置。如果您使用的是外部库或jar,则需要将其作为私有包提及。

请找到我的样本bnd.bnd文件。

Bundle-Name: ${project.artifactId}
Bundle-SymbolicName: ${project.artifactId}
Bundle-Description: Template-Bundle for developing an application
Bundle-Category: Application
Bundle-Copyright: 2017 (c) Herleraja@gmail.com
-dsannotations: *
-metatypeannotations: *
Private-Package: \
    com.jcraft,\
    com.jcraft.jsch,\
    com.jcraft.jsch.jce,\
    com.jcraft.jsch.jcraft,\
    com.jcraft.jsch.jgss,\
    com.jcraft.jzlib

我建议您使用BndTools编辑bnd.bnd文件。 你可以安装BndTools插件来从BndTool Installation.

进行eclipse

选择您需要的包。

packageselection

注意:因为如果需要任何额外的jar,它会自动不安装你需要添加的所有依赖项。即我想使用jsch,它依赖于jzlib。所以我在pom.xml文件中添加了这两个条目。

<dependency>
    <groupId>com.jcraft</groupId>
    <artifactId>jsch</artifactId>
    <version>0.1.54</version>
</dependency>


<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
<version>1.1.3</version>
</dependency>

希望这会有所帮助!请投票,以便我可以写更多的解决方案。