Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding custom string in java manifest 'Classpath' via maven pom.xml

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

like image 827
Ashish Sharma Avatar asked Aug 10 '11 07:08

Ashish Sharma


2 Answers

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>
like image 123
Michael-O Avatar answered Nov 11 '22 01:11

Michael-O


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

like image 41
Ashish Sharma Avatar answered Nov 11 '22 01:11

Ashish Sharma