Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Class-Path to the manifest file with maven

When using the maven-jar-plugin
I would like to add entry to the Manifest.mf
So it will contain:
Class-Path: .
When i add this entry to the Pom:

<Class-Path>.</Class-Path> 

It will create Class-Path with all dependency
Like:
Class-Path: . jar1name.jar jar2name.jar etc
Instead of just
Class-Path: .
Is there a way to avoid maven from adding all jar names to the Class-Path?
Thanks

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <Built-By>Me</Built-By>
            <Class-Path>.</Class-Path> 
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
like image 885
JavaSheriff Avatar asked May 15 '14 20:05

JavaSheriff


People also ask

Does Maven add to classpath?

Maven Archiver can add the classpath of your project to the manifest. This is done with the <addClasspath> configuration element.

How does Maven create the classpath?

Maven creates this classpath by considering the project's dependencies. The reported classpath consists of references to JAR files cached in local Maven repository. Even the JAR artifact of the project is referenced from local Maven cache and not from the /target directory one or the other might expect.

What is plugin tag in Maven?

Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects. They do this by executing an "action" (i.e. creating a WAR file or compiling unit tests) in the context of a project's description - the Project Object Model (POM).


1 Answers

This did the trick
Omitting the addClasspath and adding manifestEntries
Now, log4j.properties can reside outside the jar - and still be found...

                <manifest>
                    <addClasspath>true</addClasspath>
                </manifest>

This is working:

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Built-By>Me</Built-By>
             <Class-Path>.</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

Output:

 Manifest-Version: 1.0
 Archiver-Version: Plexus Archiver
 Created-By: Apache Maven
 Build-Jdk: 1.6.0_45
 Built-By: Me
 Class-Path: .
like image 176
JavaSheriff Avatar answered Sep 21 '22 08:09

JavaSheriff