Индексирование JAR с помощью maven-bundle-plugin

Я пытаюсь создать пакет с индексом (META-INF/INDEX.LIST), используя maven-bundle-plugin 2.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 не находится в target/classes, а динамически генерируется архиватором Maven.

Изменить 1

Когда я использую упаковку jar вместо упаковки bundle, индекс присутствует.

Изменить 2

Я использую Maven 3.0.4


person Philippe Marschall    schedule 21.10.2012    source источник
comment
Папки target/maven-archiver нет, только target/classes, target/test-classes, target/generated-sources, target/generated-test-sources и target/surefire-reports.   -  person Philippe Marschall    schedule 21.10.2012
comment
Я использую maven 3.0.4 и команду mvn org.apache.felix:maven-bundle-plugin:bundle, и она показывает maven-archiver в цели. Но даже я не могу создать файл INDEX.LIST. Обновлю здесь, если получу решение.   -  person Arham    schedule 21.10.2012
comment
Почему бы не использовать чистый пакет mvn?   -  person khmarbaise    schedule 22.10.2012
comment
Я использую mvn clean package, но полученная банка не имеет индекса.   -  person Philippe Marschall    schedule 23.10.2012


Ответы (1)


Порылся в исходный код maven-bundle-plugin, и похоже, что текущая версия (2.3.7) игнорирует index атрибут конфигурации архива. Он также игнорирует compress, forced и pomPropertiesFile. Единственными атрибутами конфигурации архива, на которые он обращает внимание, являются addMavenDescriptor, manifest, manifestEntries, manifestFile и manifestSections.

Я не уверен, есть ли другой способ манипулировать созданным архивом, используя только 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>

Я не очень хорошо разбираюсь в том, что требуется в пакетном архиве, поэтому вы можете перепроверить, все ли правильно.

person matts    schedule 30.10.2012