文章目录
1 场景
将maven依赖jar包和依赖jar包拷贝到指定目录
2 方案
使用maven插件maven-dependency-plugin
3 代码
3.1 目录
lib
pom.xml
downloadMvn.bat
(1)lib为空文件夹(目标文件夹)
(2)pom.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>maven.util</groupId>
<artifactId>download-jar</artifactId>
<version>1.0</version>
<!-- 要下载的maven依赖 -->
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- maven相关下载插件 -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<!-- 是否排除间接依赖。默认false,不排除 -->
<excludeTransitive>false</excludeTransitive>
<!-- 是否消除依赖jar包后缀的版本信息。默认是false,不取消版本信息 -->
<stripVersion>false</stripVersion>
<!-- 输出文件路径 -->
<outputDirectory>./lib</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
(3)downloadMvn.bat文件内容如下:
mvn dependency:copy-dependencies
3.2 执行
双击执行downloadMvn.bat
,即在pom文件路径下执行命令:
mvn dependency:copy-dependencies