使用 BND 嵌入第三方 JAR
我有一个使用 ANT 和经典 BND 工具构建的 OSGi 包。我的捆绑包在内部使用了一个库 (JAR),该库在我的 OSGi 容器 (Apache Felix) 中不能作为捆绑包使用。因此,我尝试将其嵌入到我的包中,以便在运行时访问。
如何使用 ANT+BND 嵌入这样的库/JAR? (注意:我不能使用 MAVEN,使用它可能会容易得多)
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.
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
bnd
描述符中需要两条指令。首先使用Include-Resource
将目标 JAR 包含到您的捆绑包中:然后您需要指定 foo.jar 需要位于捆绑包类路径上。我假设包内容本身也需要成为包类路径的一部分,因此我们还需要将其包含在一个点中:
请注意,@seh 的关于使用
Private-Package< 将 JAR 包放入包中的答案/code> 也是正确的(在这种情况下,JAR 需要在构建时类路径上可见)。不过,我永远不会为此使用
Export-Package
,因为我认为捆绑包应该严格控制它们导出的数量。You need two instructions in your
bnd
descriptor. First useInclude-Resource
to include the target JAR into your bundle: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:
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 useExport-Package
for this though, because I think bundles should keep tight control over how much they export.有一个 BND 提供的 Ant 任务,名为 "bndwrap"。它没有很好的记录。当我尝试使用它时,我必须阅读 Java 代码 看看它在做什么。 (参见
bnd#doWrap()
方法也在这里。)我记得还可以通过另一种方式“嵌入”依赖的 Jar 文件:不直接作为Jar-within-a-Jar,但是通过将其所有类放入您的包中,只需在您的
Private-Package
BND 指令 指示其他 Jar 提供的包应包含在您的包中。或者,您可以在Export-Package
指令中提及这些包,以将它们包含在内并导出。There is a BND-supplied Ant task called "bndwrap". It is not well documented. When I've tried to use it, I had to read the Java code to see what it was doing. (See the
bnd#doWrap()
method here as well.)I recall that it's also possible to "embed" a depended-upon Jar file another way: not directly as a Jar-within-a-Jar, but by slurping all of its classes into your bundle, simply by declaring in your
Private-Package
BND directive that the packages provided by the other Jar should be included in yours. Alternately, you can mention those packages in anExport-Package
directive to get them both included and exported.