使用 BND 嵌入第三方 JAR

发布于 2024-12-06 15:57:27 字数 203 浏览 0 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半城柳色半声笛 2024-12-13 15:57:27

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

Include-Resource: foo.jar

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

Bundle-ClassPath: ., foo.jar

请注意,@seh 的关于使用 Private-Package< 将 JAR 包放入包中的答案/code> 也是正确的(在这种情况下,JAR 需要在构建时类路径上可见)。不过,我永远不会为此使用 Export-Package ,因为我认为捆绑包应该严格控制它们导出的数量。

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

Include-Resource: 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

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.

长不大的小祸害 2024-12-13 15:57:27

有一个 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 an Export-Package directive to get them both included and exported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文