使用BND嵌入第三方JAR [英] Embed thirdparty JAR using BND

查看:171
本文介绍了使用BND嵌入第三方JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ANT和经典BND工具构建的OSGi捆绑包.我的捆绑包在内部使用一个库(JAR),但在OSGi容器(Apache Felix)中无法作为捆绑包使用.因此,我正在尝试将其嵌入我的捆绑包中,以便在运行时进行访问.

I have an OSGi bundle that is built using ANT and the classic BND tool. My bundle uses a library (JAR) internally, which is not available as a bundle within my OSGi container (Apache Felix). So, I am trying to embed it within my bundle, for access at runtime.

如何使用ANT + BND嵌入此类库/JAR? (注意:我不能使用MAVEN,使用MAVEN可能会容易得多)

How can I embed such a library/JAR using ANT+BND? (Note : I cannot use MAVEN, using which this could have been a lot easier)

推荐答案

bnd描述符中需要两条指令.首先使用Include-Resource将目标JAR包含在您的捆绑软件中:

You need two instructions in your bnd descriptor. First use Include-Resource to include the target JAR into your bundle:

Include-Resource: foo.jar

然后,您需要指定foo.jar必须位于包类路径中.我假设捆绑包内容本身也需要成为捆绑包类路径的一部分,因此我们还需要在其上加上一个点:

Then you need to specify that foo.jar needs to be on the bundle classpath. I assume that the bundle contents itself also needs to be part of the bundle classpath, so we need to include it as well with a dot:

Bundle-ClassPath: ., foo.jar

请注意,@ seh关于使用Private-Package将JAR的软件包混入捆绑包的答案也是正确的(在这种情况下,JAR必须在构建时的类路径上可见).不过,我永远不会使用Export-Package,因为我认为捆绑软件应严格控制它们的出口量.

Note that @seh's answer about slurping the JAR's packages into your bundle with Private-Package is also correct (in that case the JAR would need to be visible on the build-time classpath). I would never use Export-Package for this though, because I think bundles should keep tight control over how much they export.

这篇关于使用BND嵌入第三方JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆