“包裹”的好方法用于 OSGi 和 Maven 的 jars

发布于 2024-10-09 15:13:05 字数 542 浏览 0 评论 0原文

我正在查看 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 技术交流群。

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

发布评论

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

评论(4

半窗疏影 2024-10-16 15:13:05

我编写了一个 Maven 原型,它将帮助您将 jar 包装为 OSGI 包。

假设您想要包装 commons-collections 版本 3.2.1

首先获取原型并安装它

git clone git://github.com/HallwayTech/maven-wrap-jar-archetype.git 
cd maven-wrap-jar-archetype
maven install

然后使用原型启动您的项目。

mvn archetype:create \
  -DarchetypeGroupId=com.hallwaytech.osgi \
  -DarchetypeArtifactId=wrap-jar \
  -DarchetypeVersion=1.0-SNAPSHOT \
  -DgroupId=commons-collections \
  -DartifactId=commons-collections \
  -Dversion=3.2.1

cd commons-collections

mvn install

要部署到 Felix 内的 Apache Sling,请运行:

mvn install -Pdeploy

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

git clone git://github.com/HallwayTech/maven-wrap-jar-archetype.git 
cd maven-wrap-jar-archetype
maven install

Then use the archetype to start your project.

mvn archetype:create \
  -DarchetypeGroupId=com.hallwaytech.osgi \
  -DarchetypeArtifactId=wrap-jar \
  -DarchetypeVersion=1.0-SNAPSHOT \
  -DgroupId=commons-collections \
  -DartifactId=commons-collections \
  -Dversion=3.2.1

cd commons-collections

mvn install

To deploy to a Apache Sling inside of Felix run:

mvn install -Pdeploy
孤独陪着我 2024-10-16 15:13:05

您必须维护本地 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:

  • commons-io - simple library wrapper
  • OpenJPA - wraps the main jar and brings in the dependencies with it
爱给你人给你 2024-10-16 15:13:05

我们所做的事情与您所描述的类似。例如,我们有 Apache QPid 的内部版本。它有 6 个 jar(客户端、核心、通用、向后移植等),您很少会单独使用它们。我们有一个带有 BND 的 POM,它可以获取所有 jar,并从中生成一个 uber-osgi-jar。

步骤:

  1. 声明您的依赖项(我们有 jar,因此我们将它们声明为系统依赖项。)
  2. 导入构建插件 maven-bundle-plugin (2.1.0)
  3. 为导出、私有和导入包设置正确的指令
  4. 执行“wrap”目标“打包”阶段

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:

  1. Declare your dependencies (we have the jars, so we declared them as system deps.)
  2. Import build plugin maven-bundle-plugin (2.1.0)
  3. Set correct instructions for export, private and import packages
  4. Execution of 'wrap' goal at 'package' phase
潇烟暮雨 2024-10-16 15:13:05

我尝试了接受的答案埃里克的回答。埃里克的建议很简单,而且开箱即用。虽然,在我的例子中,它似乎产生了一个巨大的清单,然后我想起了 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.

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