1

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

我的插件配置看起来像这样

  <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它不在 Maven Archiver 中target/classes而是由 Maven Archiver 动态生成的。

编辑 1

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

编辑 2

我正在使用 Maven 3.0.4

4

1 回答 1

2

maven-bundle-plugin 源代码中挖掘,看起来当前版本(2.3.7)忽略了存档配置的index属性。它还忽略compressforcedpomPropertiesFile。它需要注意的存档配置的唯一属性是addMavenDescriptormanifestmanifestEntriesmanifestFilemanifestSections

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

作为一种可能的解决方法,您可以使用 maven-jar-plugin 在创建捆绑包后对其进行重新打包,告诉 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>

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

于 2012-10-30T16:53:39.577 回答