“包裹”的好方法用于 OSGi 和 Maven 的 jars
我正在查看 OPS4J 上的 PAX 工具,例如: 这个,我想我找到了一个很好的方法:
- 指定一个工件
- 从该 jar 及其传递依赖项创建一个组装的 jar(包含所有依赖项的 jar)
- 用 BND 包装它以创建一个OSGi 捆绑
事实证明,我错了——PAX 的东西似乎并没有做到这一点。 (RTFM,对吧?:))
但这让我想知道:有没有什么东西可以满足我的要求?
我想也许我可以通过创建一个简单的 POM 并使用 maven-bundle-plugin 来做到这一点,但这对于我的要求来说似乎有点麻烦。
注意:我知道嵌入和组装 jar 并不是真正的“OSGi 方式” - 所以我不会这样做,除非我真的觉得它有用。例如——春天。
提前致谢。
I was looking at the PAX tools on OPS4J for example: this one and I thought I'd found a nice way to:
- Specify an artifact
- Create an assembled jar (jar that contains all dependencies) from that jar and its transitive dependencies
- Wrap it with BND to create an OSGi bundle
It turns out, that I was wrong - it doesn't appear that the PAX stuff does this. (RTFM, right? :) )
But this got me wondering: is there something out there that does what I'm asking?
I've thought maybe I could do this by creating a simple POM and using the maven-bundle-plugin but this seems like it might be a bit cumbersome for what I'm asking.
NOTE: I get that embedding and assembling jar's is not really "the OSGi way" - so I wouldn't do this unless I really felt it useful. For example - Spring.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我编写了一个 Maven 原型,它将帮助您将 jar 包装为 OSGI 包。
假设您想要包装 commons-collections 版本 3.2.1
首先获取原型并安装它
然后使用原型启动您的项目。
cd commons-collections
要部署到 Felix 内的 Apache Sling,请运行:
I wrote a maven archetype that will help you wrap a jar as an OSGI bundle.
Let's say you want to wrap commons-collections version 3.2.1
First get the archetype and install it
Then use the archetype to start your project.
cd commons-collections
To deploy to a Apache Sling inside of Felix run:
您必须维护本地 POM 才能完成此任务。没有一个实用程序可以接收库/jar 并在 jar 中吐出适当的 OSGi MANIFEST。 ServiceMix 与 Spring 一起捆绑了很多东西,您可以将其用作示例。我建议查看的两个这样的示例是:
You have to maintain a local POM to get this done. There's not a utility that will take in a library/jar and spit out the appropriate OSGi MANIFEST in a jar. ServiceMix, along with Spring, have a lot of things already bundled up that you can use as examples. Two such examples I suggest looking at are:
我们所做的事情与您所描述的类似。例如,我们有 Apache QPid 的内部版本。它有 6 个 jar(客户端、核心、通用、向后移植等),您很少会单独使用它们。我们有一个带有 BND 的 POM,它可以获取所有 jar,并从中生成一个 uber-osgi-jar。
步骤:
We do something similar to what you are describing. For example, we have an internal version of Apache QPid. It comes as 6 jars (client, core, common, backports, etc) which you would rarely use individually. We have one POM with BND which takes all the jars, and makes one uber-osgi-jar from them.
Steps:
我尝试了接受的答案和埃里克的回答。埃里克的建议很简单,而且开箱即用。虽然,在我的例子中,它似乎产生了一个巨大的清单,然后我想起了 p2-maven-插件。最后一种方法在很多情况下都非常有效。如果您需要的工件已经是捆绑包,或者它的依赖项是捆绑包,那么它只需将它们放入它构建的存储库中。如果没有,它将运行 maven-bundle-plugin< /a> 使用一些默认设置(或者您可以配置您需要的设置)。非常酷!
我特别喜欢它抓住传递依赖并处理这些依赖。如果您不需要存储库,但只是在打包后的捆绑包之后,那么从
target/repository/plugins
文件夹中挑选它是一件简单的事情。I tried The accepted answer and Erik's answer. Erik's suggestion was simple and worked right out the box. Although, it seemed to produce a huge MANIFEST in my case, and then I recalled the p2-maven-plugin. This last method works very well in a large number of cases. If the artifact you need is already bundle, or its dependencies are bundles it simply puts them into the repo it builds. If not, it will run maven-bundle-plugin with some default settings (or you can configure the settings you need). Very cool!
I especially like that it grabs the transitive dependencies and takes care of those too. If you don't need the repo, but are just after the wrapped bundle, it is a simple matter to go cherry pick it out of
target/repository/plugins
folder.