5

I am creating a manifest file for my java jar via following pom.xml directives:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                         <mainClass>parser.BulkParser</mainClass>
                         <classpathPrefix>dependency/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>                
        </plugin>
    </plugins>
</build>

this results in following kind of manifest to be generated:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: shaashis
Build-Jdk: 1.6.0_21
Main-Class: parser.BulkParser
Class-Path: dependency/commons-configuration-1.6.jar dependency/commons-collections-3.2.1.jar dependency/commons-lang-2.4.jar

Here I want to add a string of following type in the Class-Path:

Class-Path: conf/ dependency/commons-configuration-1.6.jar dependency/commons-collections-3.2.1.jar dependency/commons-lang-2.4.jar

How can I do that via my pom.xml?

thanks

Ashish

Ashish Sharma
  • 1,124
  • 2
  • 24
  • 49

2 Answers2

14

Altering The Classpath: Using a Custom Classpath Format is the way to go.

Edit: The above does not exactly what is desired. I have found a way to achive that by examining the Archiver source code. This will do (just verified in the shell):

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifestEntries>
                <Class-Path>conf/</Class-Path>
            </manifestEntries>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
            </manifest>
        </archive>
    </configuration>
</plugin>
Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • I don't think "this" is what the OP asked for. Your link points to the Maven war plugin, while the OP has a simple jar. – Nicola Musatti Aug 10 '11 at 09:29
  • Laziness is a bad desease. The link leads to the Maven Archiver which is used in every packaging project such as jar or war. – Michael-O Aug 10 '11 at 09:54
  • The fact that I was confused by the mention of the maven-war-plugin reference in the configuration you linked doesn't give you the right to be offensive. – Nicola Musatti Aug 10 '11 at 10:18
  • Please consider including a summary of the link information to avoid link rot in the future. – staticbeast Aug 10 '11 at 11:52
  • Already looked into your suggestion Michael, this was not working, this results in repeating the string with every dependency class path – Ashish Sharma Aug 10 '11 at 14:14
6

Modified my pom.xml as follows to get the correct solution to my problem:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>parser.BulkParser</mainClass>
                        <classpathPrefix>dependency/</classpathPrefix>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>conf/</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

this resulted in generating the value of 'Class-Path' in the manifest file as I wanted.

References:

Manifest Entries

Maven Archiver

Ashish Sharma
  • 1,124
  • 2
  • 24
  • 49