【问题标题】:Indexing a JAR using maven-bundle-plugin使用 maven-bundle-plugin 索引 JAR
【发布时间】:2012-10-21 08:25:53
【问题描述】:

我正在尝试使用 maven-bundle-plugin 2.3.7 构建具有索引 (META-INF/INDEX.LIST) 的包。

我的插件配置是这样的

  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
      <archive>
        <index>true</index>
      </archive>
      <instructions>
        <!-- other things like Import-Package -->
        <Include-Resource>{maven-resources}</Include-Resource>
      </instructions>
    </configuration>
  </plugin>

META-INF/INDEX.LIST 不会出现在 JAR 中。我尝试使用

  <Include-Resource>{maven-resources},META-INF/INDEX.LIST</Include-Resource>

但这会失败

[ERROR] Bundle com.acme:project::bundle:1.0.0-SNAPSHOT : Input file does not exist: META-INF/INDEX.LIST
[ERROR] Error(s) found in bundle configuration

这并不奇怪,因为META-INF/INDEX.LIST 不在target/classes 中,而是由 Maven Archiver 动态生成的。

编辑 1

当我使用 jar 而不是 bundle 包装时,索引就在那里。

编辑 2

我正在使用 Maven 3.0.4

【问题讨论】:

  • 没有target/maven-archiver文件夹,只有target/classestarget/test-classestarget/generated-sourcestarget/generated-test-sourcestarget/surefire-reports
  • 我正在使用 maven 3.0.4 和命令“mvn org.apache.felix:maven-bundle-plugin:bundle”,它确实在目标中显示了一个 maven-archiver。但即使我无法生成 INDEX.LIST 文件。如果我得到解决方案,将在此处更新。
  • 为什么不使用 mvn clean package ?
  • 我正在使用mvn clean package,但生成的 jar 没有索引。

标签: java maven bnd maven-bundle-plugin


【解决方案1】:

maven-bundle-plugin source code 中四处寻找,它看起来像当前版本(2.3.7)忽略存档配置的index 属性。它还会忽略 compressforcedpomPropertiesFile。它确实关注的存档配置的唯一属性是addMavenDescriptormanifestmanifestEntriesmanifestFilemanifestSections

我不确定是否有任何其他方法可以仅使用 maven-bundle-plugin 来操作创建的存档。

作为一种可能的解决方法,您可以在创建包后使用 maven-jar-plugin 重新 jar 包,告诉 jar 插件创建索引,但使用包插件创建的清单。

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <!-- unpack bundle to target/classes -->
        <!-- (true is the default, but setting it explicitly for clarity) -->
        <unpackBundle>true</unpackBundle>
        <instructions>
            <!-- ... your other instructions ... -->
            <Include-Resource>{maven-resources}</Include-Resource>
        </instructions>
    </configuration>
</plugin>
<!-- List this after maven-bundle-plugin so it gets executed second in the package phase -->
<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <!-- overwrite jar created by bundle plugin -->
                <forceCreation>true</forceCreation>
                <archive>
                    <!-- use the manifest file created by the bundle plugin -->
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    <!-- bundle plugin already generated the maven descriptor -->
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <!-- generate index -->
                    <index>true</index>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

我对捆绑存档中的要求不太熟悉,因此您可能需要仔细检查一切是否正确。

【讨论】:

    猜你喜欢
    • 2016-07-20
    • 2010-11-25
    • 2013-08-19
    • 2014-02-08
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 2012-09-18
    • 2013-02-10
    相关资源
    最近更新 更多