java 将依赖打包进lib_maven把依赖包拷贝到lib下

标准web工程在eclipse中利用m2eclipse插件添加依赖管理后,在部署过程中没有将依赖的jar包自动拷贝到/WEB-INF/lib中。

参考了一些朋友的做法手动执行

mvn dependency:copy-dependencies -DoutputDirectory=src/main/webapp/WEB-INF/lib  -DincludeScope=runtime

命令将jar包拷贝到/WEB-INF/lib目录下。

这种做法固然可以,但是也会带来一些不便。

1、需要手动执行命令。

2、不能时时更新。

以下列出网上查找到的解决方法,m2eclipse plugin方式已验证通过。

通过验证eclipse版本:eclipse-jee-helios-SR2-win32

m2eclipse插件地址:http://m2eclipse.sonatype.org/sites/m2e

标准web工程通过m2eclipse添加依赖管理步骤:

1、“Maven ” –> “Enable dependency Management“

2、Web Deployment Assembly中添加maven dependencies

步骤如下图:

工程 -> 右键 -> preferences

11388_1305885043ppea.jpg

11388_1305885043l5DF.jpg

11388_1305885044j8hQ.jpg

11388_1305885044K66T.jpg

.classpath文件中会有修改

(执行“Maven ” –> “Update Project Configuration “未生效,故手动添加。必须deploy时候才会拷贝jar包到lib目录下,而非在更新maven依赖时候拷贝jar包。 )

以下为原文内容:

Published: September 3, 2010 , Updated: September 3, 2010 , Author: mkyong

Problem

In Eclipse 3.5 or early version, in order to deployed the Maven dependencies to the correct “/WEB-INF/lib ” folder, you have to configure the dependencies via “Java EE Module Dependencies”, and the updated “.classpath ” file will look like following :

File : “.classpath”, by Java EE Module Dependencies…

...

sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar">

...

Since Eclipse 3.6, the “Java EE Module Dependencies” is replaced by

“Web Deployment Assembly”, but you can do the same via the “Referenced

Projects Classpath Entries”, however, it will update the “.classpath ” file as following :

File : “.classpath”, by Web Deployment Assembly…

...

sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar">

...

Sadly, the default (value=”../”) makes all the Maven’s dependencies failed to deploy.

Solution

Not a big issue, you still can modify the (value=”../”) to (value=”/WEB-INF/lib”) manually, but it will get override every time you run a Maven build. No worry, there are still have two solutions :

1. WTP Support

Ignore the “Referenced Projects Classpath Entries” settings, instead, make the Maven supports WTP 2.0

mvn eclipse:eclipse -Dwtpversion=2.0

It will generate a new file named “org.eclipse.wst.common.component “, under “settings ” folder, see a portion of this file :

File : “org.eclipse.wst.common.component”, by WTP

...

handle="module:/classpath/var/M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar">

uses

...

With WTP support, it helps to deploy the Maven dependencies to “/WEB-INF/lib ” folder correctly.

2. m2eclipse plugin

Install the m2eclipse

, an Eclipse plugin to integrate Maven into the Eclipse IDE. After the

installation, right click on the project folder, select “Maven ” –> “Update Project Configuration “, it will update the “.classpath ” file accordingly, see a snippet

File : “.classpath”, by m2eclipse

...

...

It helps to deploy the Maven dependencies correctly as well.

Reference

http://blog.csdn.net/yirentianran/article/details/6429240

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值