这期内容当中小编将会给大家带来有关Maven项目实现打Jar包并添加依赖,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

使用maven-dependency-plugin插件
子项目中的pom.xml文件中,添加以下maven-dependency-plugin依赖,这个maven-dependency-plugin依赖的作用就是自动拷贝jar包到target目录
这是我的Maven子项目打包,指定了将它的依赖的父项目中的jar包拷贝到target下的lib目录
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- ${project.build.directory}为Maven内置变量,缺省为target -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>