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

查看:52
本文介绍了使用 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,使用它可能会容易得多)

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 关于将 JAR 包放入带有 Private-Package 的包中的回答也是正确的(在这种情况下,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天全站免登陆