0

I am working on java project with Maven and Maven-jar-plugin I have generated a classpath of dependencies for my jar file in MANIFEST.MF using maven jar plugin. here is my plugin usage:

      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <Build-Time>${maven.build.timestamp}</Build-Time>
                    </manifestEntries>
                    <manifestSections>
                        <manifestSection>
                            <name>${project.name}</name>
                            <manifestEntries>
                                <git-branch>${git.branch}</git-branch>
                                <git-build-host>${git.build.host}</git-build-host>
                                <git-build-time>${git.build.time}</git-build-time>
                                <git-build-user-email>git.build.user.email</git-build-user-email>
                                <git-build-user-name>git.build.user.name</git-build-user-name>
                                <git-build-version>${git.build.version}</git-build-version>
                            </manifestEntries>
                        </manifestSection>
                    </manifestSections>
                </archive>
            </configuration>
  </plugin

and the generated classpath is like this:

 Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Build-Time: 2020-01-23T13:34:14Z
Class-Path: org/apache/logging/log4j/log4j-api-2.6.2.jar 
org/apache/logging/log4j/log4j-core-2.6.2.jar
org/apache/commons/commons-configuration2-2.2.jar org/apache/commons/commons-lang3-3.6.jar
commons-loggin g/commons-logging-1.2.jar
commons-beanutils/commons-beanutils-1.9.3.jar
commons-collections/commons-collections-3.2.2.jar 
Created-By: Apache Maven 3.6.2
Build-Jdk: 1.8.0_181

Name: service_utils
git-commit-id-abbrev: d78e66c

but I do need to generate my classpath with relative path and not path throughthe lib or WEB-INF. I am looking to have something like this:

Manifest-Version: 1.0
Class-Path: 
../../../org/hibernate/hibernate-core/5.1.0.Final/hibernate-core-5.1.0.Final.jar ../artifacts/org/hibernate/hibernate-core/5.1.0.Final/hibernate-core-5.1.0.Final.jar ../../../org/hibernate/common/hibernate-commons-annotations/5.0.1.Final/hibernate-commons-annotations-.0.1.Final.jar
../artifacts/org/hibernate/common/hibernat e-commons-annotations/5.0.1.Final/hibernate-commons-annotations-5.0.1 .Final.jar
../../org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar 
../artifacts/org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar 
../../../com/mchange/c3p0/ 0.9.2.1/c3p0-0.9.2.1.jar

I have searched and studied so many of StackOverflow's questions regarding having manifest file in a jar file with their relative path classpath, I have seen options for gradle but I am looking for maven solution and better if I can perform this with maven jar plugin.

Fardin Behboudi
  • 459
  • 4
  • 15

1 Answers1

0

I found a way to get the relative address, but the depth is hardcoded and it will not be a perfect solution for multimodule projects.

<manifest>                                 
     <addClasspath>true</addClasspath>
     <mainClass>My.Main</mainClass>
     <classpathLayoutType>custom</classpathLayoutType> 
 <customClasspathLayout>../../../$${artifact.groupIdPath}/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension} ../artifacts/$${artifact.groupIdPath}/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>
</manifest>
Fardin Behboudi
  • 459
  • 4
  • 15