17

使用 Maven 开发 OSGi 应用程序时有两种主要方法:POM-first 和 MANIFEST first。

我正在寻找以表格形式显示每种方法的优缺点的答案。

更具体地说,我还想知道它与:

  • 工具集的成熟度
  • 供应商独立性
  • 易于开发(包括寻找可以在工具上进行开发的人)
  • 兼容性
  • 避免 ClassNotFound
  • 避免手工作业
4

3 回答 3

18

目前这是我能想到的

POM-First Pros(使用 maven-bundle-plugin)

  • 利用现有的 Maven 技能、存储库和工具。
  • 可能更容易找到知道如何管理 pom.xml 而不是 MANIFEST.MF 和 pom.xml 的人
  • MANIFEST.MF 中的大部分信息都可以从 pom.xml 本身获取。
  • 可以与其他 IDE 一起工作,而不仅仅是基于 Eclipse 的。
  • 侵入性较小,只需添加单个插件并将打包类型更改为“捆绑”

POM 优先缺点

  • ClassNotFoundException更有可能在运行时发生。但是,可以使用 pax-exam 来缓解这种情况(尽管设置起来非常复杂)。
  • 仍然需要了解 MANIFEST 是如何设置的,以确保instructions配置元素设置正确。

清单优先的优点(使用 tycho-maven-plugin)

  • 似乎是推荐的方法,或者至少被称为推荐的方法,但我真的不明白为什么它有显着的好处。(因此为什么要问这个问题)。
  • 适合开发 Eclipse 插件并与 PDE 很好地集成
  • Provides tooling for testing thus allowing ClassNotFoundException to appear during JUnit testing rather than runtime.

MANIFEST-first Cons

  • Seems to only work well on Eclipse based IDEs. You don't have to use Eclipse, but without the PDE would you want to?
  • Violates DRY principles since I have to do put keep the names and versions from the POM and MANIFEST.MF in sync.
  • Need to name things in a specific fashion
  • You cannot mix, meaning existing Maven multi-project installations cannot just tack on OSGi support
  • A lot more configuration compared to maven-bundle-plugin is needed to get less warnings: http://wiki.eclipse.org/Tycho/Reference_Card#Examplary_parent_POM
  • Have to make test cases a separate project. It won't run when built in src/test/java.
  • Seems that it will only test classes that are exposed, in other words those in ".internal." is not testable.

If I were asked for a recommendation for an enterprise that is using Maven already and want to move to OSGi then it would be POM first

If I were asked for a recommendation for someone who is doing Eclipse plugin development, then it is Manifest first -- with tycho

于 2012-07-07T07:04:32.713 回答
6

I think you should choose by use case. For server side OSGi projects I favour the pom first style. It nicely matches the maven builds and is much less error prone than Manifest first. In fact bnd which is behind the maven bundle plugin gets the Manifest right for most cases without any additional config. The trick is to use some naming rules. For example if you name internal package impl or internal the will not be exported. Using this style you can not use the Eclipse plugin perspective (at least without bndtools which I do not like) but I did not yet miss this perspective. I am a developer in the Apache Karaf, CXF and Camel projects where we use this style and it works great. Especially for CXF and Camel it is great that we can support OSGi and non OSGi deployments with the same build and tools.

For Eclipse RCP applications Manifest first is the way to go as you need the plugin perspective and the Eclipse IDE tools. If you want to combine that with maven then tycho is probably the way to go.

于 2012-07-07T21:08:00.317 回答
0

MANIFEST first does not lock you to Eclipse (although I'd be surprised if more than a tiny minority would use anything else). The MANIFEST is the file that counts, and needs to be added to a jar, regardless how you do that.

On the other hand, POM first completely locks you to Maven, you lose the advantage that an OSGi bundle is a regular jar you can make any way you want.

I've tried both, I really prefer MANIFEST first. The MANIFEST file is a really important file, I prefer to craft that file over crafting a file that produces that file. If something weird happens, (and it will at some point) the MANIFEST file is the first to check, it's just easier if it's your own file. Besides, you will have to be familiar with it anyway.

So, if Maven is your alpha and omega, POM first will suit you best, but you'll still need to have in-depth understanding of the MANIFEST file.

于 2012-07-07T08:42:24.107 回答