我的jar文件名在pom.xml中配置如下:
MyApp-1.0.3.jar
我希望Maven('mvn package')在每次运行时为当前jar文件创建一个符号链接,这样我就有两个文件:
MyApp.jar
"ln -s MyApp-1.0.3.jar MyApp.jar"
(S3_BUCKET_NAME
)
答案 0 :(得分:3)
您可以使用以下Exec Maven Plugin来实现此目标:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Version Calculation</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>ln</executable>
<arguments>
<argument>-fnsv</argument>
<argument>target/MyApp-${project.version}.jar</argument>
<argument>MyApp.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
使用以下目标执行它:
mvn clean verify
答案 1 :(得分:-1)
您可以使用ant-run插件的符号链接任务/目标
<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>
如果希望符号链接具有相对路径,则可以在资源中提供相对路径,如下所示
<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>