Eclipse 覆盖由 maven bundle 插件创建的清单

Eclipse overwrites manifest created by maven bundle plugin

我正在使用 maven-bundle-plugin 为 OSGi 容器生成 MANIFEST.MF。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Export-Package>com.example.mypackage</Export-Package>
                </instructions>
            </configuration>
            <executions>
                <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

但是,在 f.g Maven/Update 项目或 Clean/Build.

之后,该清单文件被 Eclipse (4.6.1 Neon) 破坏(覆盖)

是否可以让 Eclipse 以某种方式知道 maven 插件,而不破坏它们的输出?我应该设置什么来防止这种(错误)行为?

如果该问题不能通过 Eclipse 解决,那么使用 IntelliJ 会更好吗? IDE 中的 OSGi 支持对我来说非常重要...

我必须更改我的答案。我错过了您定义目标清单的部分。这是使用 maven bundle plguin 的新推荐方法,但它需要您告诉 jar 插件使用现有的清单。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>

旧答案

我怀疑您使用的是 Eclipse PDE。 PDE 始终首先运行 Manifest。这意味着它与 maven-bundle-plugin 不兼容。

我建议使用我们在 Apache 项目(如 Apache Karaf 或 Apache Aries)中经常使用的纯 maven 构建。它缺少 Eclipse PDE 的特殊 OSGi 支持,但无论如何都很糟糕。

您可以使用 eclipse 插件 bndtools 来增强它。 Bndtools 现在在一定程度上提供 Maven 支持。这意味着您现在可以为您的项目提供基于 Maven 的 OBR 索引,并定义要在 bndrun 文件中启动的包。这允许在 Eclipse 中直接启动和调试您的 OSGi 项目。请参阅 osgi-chat example 如何操作。

请注意,bndtools 最近刚刚开始提供 Maven 支持。所以现在的3.3.0版本还是缺少一些maven构建的便利性

根据我的配置:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>3.3.0</version>
    <extensions>true</extensions>
    <configuration>
      <manifestLocation>src/main/resources/META-INF</manifestLocation>
      <rebuildBundle>true</rebuildBundle>
      <instructions>
        <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
      </instructions>
    </configuration>
  </plugin>

并且安装了插件: m2e 连接器:http://download.eclipse.org/m2e-wtp/releases/neon/ BND 工具:http://bndtools.org/

Eclipse 构建终于没有破坏清单文件。但是有一些迭代(maven 构建、更新 Maven 依赖项、Eclipse 构建、maven 构建)是必要的。同样事先,我删除了文件系统上所有与项目相关的设置:.classpath、.project、.factorypath、.settings、.apt_generated、target。希望对您有所帮助。