Create symlink to the current jar package after mvn package

Viewed 4340

My jar file name is configured in pom.xml like this:

<finalName>MyApp-${project.version}</finalName>

I would like Maven ('mvn package') to create a symlink to the current jar file every time I run it, so that I have two files:

MyApp-1.0.3.jar
MyApp.jar (which is "ln -s MyApp-1.0.3.jar MyApp.jar")

2 Answers

You can use symlink task/goal of ant-run plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <target>
                    <symlink link="${project.build.directory}/${project.artifactId}.jar"
                             resource="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

If you want the symlinks to have relative path, you can give relative path in resource like below

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <target>
                    <symlink link="${project.build.directory}/${project.artifactId}.jar"
                             resource="./${project.artifactId}-${project.version}.jar"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Related