使用 maven-bundle-plugin 将 JAR 嵌入到 OSGi 包中

发布于 2024-08-04 01:22:51 字数 476 浏览 5 评论 0原文

我正在尝试使用 maven-bundle-plugin

让我担心的是,所有嵌入 JAR 的包都被放入生成的 MANIFEST.MF 的 Import-Package 标头中。

如果我明确指定仅使用我需要的包,如以下代码片段所示:

Import-Package: org.osgi.framework

构建失败并出现 BND 错误(未解析的引用)。

那么,这里的问题是如何构建带有嵌入式 JAR 的捆绑包以及我需要的“Import-Package”标头?

I’m trying to embed some JARs into single OSGi bundle using the feature of maven-bundle-plugin

The thing that worries me is that all packages of embedded JARs are put into the Import-Package header of the generated MANIFEST.MF.

If I specify explicitly to use only the packages I need, like in the following snippet:

Import-Package: org.osgi.framework

The build fails with BND error (unresolved references).

So, the question here is how can I build the bundle with embedded JARs with "Import-Package" header I need?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

三生池水覆流年 2024-08-11 01:22:51

您的类中导入的所有包都将由 bnd 导入。也许您不希望导入这些包,因为知道在运行时您将不需要它们。如果您无法阻止 bnd 导入它们,则可以将它们设置为可选,以便您的包仍然可以解析,即使它们不是由另一个包提供的(在传输时)。尝试添加以下内容:

<Import-Package>*;resolution:=optional<Import-Package>

到 maven 中的 maven bnd 配置中。

All the packages that are imported in your classes will be imported by bnd. Perhaps you do not want those packages imported because you know that at runtime you won't be needing them. If you cannot stop bnd from importing them, you can make them optional so that your bundle will still resolve even if they are not supplied by another bundle (at wire time). Try to add this:

<Import-Package>*;resolution:=optional<Import-Package>

To your maven bnd configuration in maven.

缺⑴份安定 2024-08-11 01:22:51

您在 Import-Package 标头中看到“意外”包的一个可能原因如下:

支持 OSGi 中协作模型的一般良好实践是导入您导出的所有包 - 请参阅Peter Kriens 的这篇博客文章了解详细说明为什么。 Bnd(以及 maven-bundle-plugin)默认遵循这种做法,并自动导入所有导出的包。因此,您应该首先检查 Export-Package 标头并确保仅导出所需的包。

另外,如果您想从嵌入式依赖项中导出包,那么您应该小心避免包内出现重复 - 请参阅 maven-bundle-plugin 文档的嵌入依赖项和导出包

One possible reason why you are seeing "unexpected" packages in Import-Package header is the following:

A general good practice that supports collaboration model in OSGi is to import all packages that you export -- see this blog post by Peter Kriens for detailed explanation why. Bnd (and hence also maven-bundle-plugin) follows this practice by default and automatically imports all exported packages. Therefore you should first check your Export-Package header and make sure that you export only the packages you want.

Also if you want to export packages from the embedded dependencies then you should be careful to avoid duplication inside your bundle -- see section Embed-Dependency and Export-Package of the maven-bundle-plugin documentation.

老街孤人 2024-08-11 01:22:51

如果您想让类在包含 JAR 的包中可用,则应该使用 Bundle-ClassPath,例如,

Bundle-ClassPath: foo.jar,other.jar
Import-Package: org.osgi.framework,org.other.imported

您需要列出 foo.jar 和 other.jar 导入/使用的类,但不需要列出任何foo.jar 或 other.jar 中的包,除非您实际导出它们。

You should use Bundle-ClassPath if you want to make classes available inside a bundle that contains JARs e.g.

Bundle-ClassPath: foo.jar,other.jar
Import-Package: org.osgi.framework,org.other.imported

You'll need to list the classes that foo.jar and other.jar import/use, but you won't need to list any of the packages in foo.jar or other.jar unless you're actually exporting them.

知足的幸福 2024-08-11 01:22:51

当您将 JAR 嵌入到捆绑包中时,您可以从导入包范围中删除一些包:

<Import-Package>![package_name9]<Import-Package>

在 pom.xml 内或者如果您使用外部 *.bnd 文件:

Import-Package: ![package_name]

You can remove some packages from import-package scope when you embed a JAR into your bundle:

<Import-Package>![package_name9]<Import-Package>

inside pom.xml or if you use external *.bnd files:

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