Maven管理的jar没有发布到WEB-INF/lib下的解决方案

标准web工程通过m2eclipse添加依赖管理步骤:
1、“Maven ” –> “Enable dependency Management“

2、Web Deployment Assembly中添加maven dependencies

步骤如下图:

工程 -> 右键 -> preferences

 

 

 

 


.classpath文件中会有修改

   

[xhtml]  view plain copy
  1.   

[xhtml]  view plain copy
  1.   
  2.           
  3.               
  4.           
  5.       

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

以下为原文内容:

 

Eclipse : Web Deployment Assembly & Maven dependencies issue

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

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…

[xhtml] view plaincopy
  1. ...  
  2.    sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar">  
  3.      
  4.        
  5.      
  6.   
  7. ...  

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…

[xhtml] view plaincopy
  1. ...  
  2.    sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar">  
  3.      
  4.        
  5.      
  6.   
  7. ...  

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

[java]  view plain copy
  1. 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

[xhtml] view plaincopy
  1. ...  
  2.   handle="module:/classpath/var/M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar">  
  3.   uses  
  4.   
  5. ...  

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

[xhtml] view plaincopy
  1. ...  
  2.   
  3.     
  4.       
  5.     
  6.   
  7. ...  

It helps to deploy the Maven dependencies correctly as well.

Reference

  1. http://m2eclipse.sonatype.org/
  2. http://www.mkyong.com/maven/maven-dependency-libraries-not-deploy-in-eclipse-ide/
  3. http://www.eclipse.org/forums/index.php?t=msg&goto=542963&
  4. http://www.eclipse.org/forums/index.php?t=msg&goto=543308&
  5. http://tux2323.blogspot.com/2010/06/review-eclipse-helios-rc4.html


你可能感兴趣的:(Maven管理的jar没有发布到WEB-INF/lib下的解决方案)