如何让maven 将工程依赖的jar 复制到自定义目录下

1.在默认生命周期的compile阶段执行 maven-dependency-plugin:copy-dependencies命令即可:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

2.当依赖jar包发生变更时,应该执行clean生命周期,删除所有旧的jar包;这样才能保证WEB-INF/lib和Maven的依赖管理的Jar包一致。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>clean</id>
<phase>pre-clean</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<directory>src/main/webapp/WEB-INF/lib</directory>
</configuration>
</execution>
</executions>
</plugin>

项目路径:

${project.build.directory}

另一种方法:

一、导出到默认目录 targed/dependency
从Maven项目中导出项目依赖的jar包:进入工程pom.xml 所在的目录下,执行如下命令:

mvn dependency:copy-dependencies

或在eclipse中,选择项目的pom.xml文件,点击右键菜单中的Run As,见下图红框中,在弹出的Configuration窗口中,输入 dependency:copy-dependencies后,点击运行
maven项目所依赖的jar包会导出到targed/dependency目录中。

二、导出到自定义目录中
在maven项目下创建lib文件夹,输入以下命令:

mvn dependency:copy-dependencies -DoutputDirectory=lib

maven项目所依赖的jar包都会复制到项目目录下的lib目录下

三、设置依赖级别
同时可以设置依赖级别,通常使用compile级别

 mvn dependency:copy-dependencies -DoutputDirectory=lib   -DincludeScope=compile

转载于:https://my.oschina.net/yiqifendou/blog/907222

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值