这是 maven 的方式,通过maven插件实现 jar 包复制到指定目录。
在最外层 pom 文件下定义变量
<properties>
......
<copy.jar.directory>D:/jar-output</copy.jar.directory>
</properties>
在对应服务的 pom 文件下添加 plugin。
<build>
<plugins>
<!-- 把jar包拷贝到指定目录位置 -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<configuration>
<target>
<copy todir="${copy.jar.directory}">
<fileset dir="${project.build.directory}">
<include name="${project.artifactId}.jar" />
</fileset>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
网上常见的是在 configuration 中使用 tasks 标签,但是在新版本中 tasks 已经被移除了
You are using 'tasks' which has been removed from the maven-antrun-plugin. Please use 'target' and refer to the >>Major Version Upgrade to version 3.0.0<< on the plugin site.
这里使用了 target 来替代。