Indexing a JAR using maven-bundle-plugin

2.8k views Asked by At

I'm trying to build a bundle that has an index (META-INF/INDEX.LIST) using maven-bundle-plugin 2.3.7.

My plugin configuration looks like this

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

but META-INF/INDEX.LIST will not show up in the JAR. I tried to use

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

but that will fail with

[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

which is not surprising because META-INF/INDEX.LIST is not in target/classes but dynamically generated by the Maven Archiver.

Edit 1

When I use jar instead of bundle packaging then the index is there.

Edit 2

I'm using Maven 3.0.4

1

There are 1 answers

0
matts On BEST ANSWER

Dug around in the maven-bundle-plugin source code, and it looks like the current version (2.3.7) ignores the index attribute of the archive configuration. It also ignores compress, forced, and pomPropertiesFile. The only attributes of the archive configuration it does pay attention to are addMavenDescriptor, manifest, manifestEntries, manifestFile, and manifestSections.

I'm not sure if there is any other way to manipulate the created archive using only maven-bundle-plugin.

As a possible workaround, you might be able to use the maven-jar-plugin to re-jar the bundle after it's created, telling the jar plugin to create an index, but use the manifest created by the bundle plugin.

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

I'm not too familiar with what's required in a bundle archive, so you might want to double check that everything is correct.