使用maven-bundle-plugin索引JAR

时间:2012-10-21 08:25:54

标签: java maven bnd maven-bundle-plugin

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

我的插件配置如下所示

  <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

1 个答案:

答案 0 :(得分:2)

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

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

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

<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>

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