How to add Class-Path to the manifest file with maven
Asked Answered
G

1

18

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>
Glennieglennis answered 15/5, 2014 at 20:31 Comment(2)
generally jars you don't want in classpath at runtime are marked as provided, does it solve your case?Spinescent
I don't want any jar on the Class-Path in the manifest, provided or not, I just want to output "."Glennieglennis
G
32

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: .
Glennieglennis answered 15/5, 2014 at 21:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.