使用maven管理java项目的时候,有时候需要将依赖的第三方jar包一起打包发布,这就用到了maven-dependency-plugin插件,全称
org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies
在pom文件中增加该插件的声明,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration> <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<copyPom>true</copyPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
执行Mvn package之后就可以将依赖的jar拷贝到dependencies目录,并且会将jar的pom一并拷贝下载。