使用maven打包jar的时候,默认是把各个项目的jar输入到各自的target目录下。而如果一个项目中包含有N个子项目,人工去把一个个的jar复制出来就太蛋疼了,好在maven有一个maven-antrun-plugin提供了集中复制jar包到指定文件夹的功能。具体用法如下:
test是父项目,hello和helloworld是test的子项目,child1ofhello是hello的子项目
-test
|-hello
| |
| |-child1ofhello
|
|-helloworld
在父项目的pom.xml中添加以下内容
<properties>
<!-- properties中定义jar包的保存路径-->
<project.jar.output.directory>D:\Documents\sourcecode\Java\test\target2</project.jar.output.directory>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<!-- 在maven进行package的时候执行-->
<phase>package</phase>
<configuration>
<tasks>
<!--jar包保存位置 -->
<copy todir="${project.jar.output.directory}">
<!--antrun自动生成的配置文件的保存位置,这里默认是父项目的target文件夹 -->
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
设置好用使用maven进行package,可以看到在jar包全部被复制到了父项目的指定目录