【问题标题】:Eclipse overwrites manifest created by maven bundle pluginEclipse 覆盖由 maven bundle 插件创建的清单
【发布时间】:2017-05-24 15:57:05
【问题描述】:

我正在使用 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 Project 或 Clean/Build 之后,该清单文件被 Eclipse (4.6.1 Neon) 破坏(覆盖)。

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

如果这个问题不能用 Eclipse 来解决,例如,它用 IntelliJ 会更好吗? IDE 中的 OSGi 支持对我来说非常重要...

【问题讨论】:

    标签: eclipse maven osgi


    【解决方案1】:

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

            <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 不兼容。

    我建议使用简单的 maven 构建,我们在 Apache Karaf 或 Apache Aries 等 apache 项目中经常使用这种构建。它缺乏 Eclipse PDE 的特殊 OSGi 支持,但这很糟糕。

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

    请注意,尽管 bndtools 最近才开始支持 maven。所以当前版本 3.3.0 仍然缺乏一些 maven 构建的便利。

    【讨论】:

    • 我不是故意使用 Eclipse PDE。它可能是开箱即用的,或者被 maven 插件激活...
    • 如果你喜欢首先使用 MANIFEST.MF,你需要在 Maven 中使用一些东西来处理它,比如 Tycho Maven...
    【解决方案2】:

    根据我的配置:

    <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 build、Update Maven Dependencies、Eclipse Build、maven build)是必要的。同样事先,我删除了文件系统上所有与项目相关的设置:.classpath、.project、.factorypath、.settings、.apt_generated、target。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-13
      • 2018-05-24
      • 1970-01-01
      • 2011-12-23
      • 1970-01-01
      • 2013-12-28
      • 2019-12-22
      • 2011-06-28
      相关资源
      最近更新 更多