javamavenmaven-dependency-pluginmaven-jar-plugin

How to append folder to each classpath entry using maven dependency and jar plugin?


I am trying to append folder before for all classpath entries in manifest file.

As you can see in pom file below, I am using jar plugin to add classpath entries to manifest.

With dependency plugin I am copying dependencies to ${project.build.directory}/${finalName}-lib folder.

I want to keep these dependencies in that folder and change classpath entries to match ${finalName}-lib folder path.

pom:

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <finalName>${jarpluginoutput}</finalName>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>desktop.core.Main</mainClass>
                    </manifest>
                </archive>
                <excludes>
                    <exclude>log4j2-test.properties</exclude>
                    <exclude>**/.keep</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.2.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <includeScope>compile</includeScope>
                        <outputDirectory>${project.build.directory}/${finalName}-lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

Solution

  • Solution is made by adding <classPathPrefix>.

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <finalName>${jarpluginoutput}</finalName>
                    <archive>
                        <manifest>
                            <classpathPrefix>${finalName}-lib</classpathPrefix>
                            <addClasspath>true</addClasspath>
                            <mainClass>desktop.core.Main</mainClass>
                        </manifest>
                    </archive>
                    <excludes>
                        <exclude>log4j2-test.properties</exclude>
                        <exclude>**/.keep</exclude>
                    </excludes>
                </configuration>
            </plugin>