Eclipse : Web Deployment Assembly & Maven dependencies issue
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…
...
<classpathentry kind="var" path="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar"
sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
...
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…
...
<classpathentry kind="var" path="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar"
sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="../"/>
</attributes>
</classpathentry>
...
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
...
<dependent-module archiveName="jsp-api-2.1.jar" deploy-path="/WEB-INF/lib"
handle="module:/classpath/var/M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
...
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
...
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
...
It helps to deploy the Maven dependencies correctly as well.
Thanks for 2nd solution, m2eclipse plugin.
Thanks for the info. very helpful.
Hi!
Hey I have a web proyect and a Java application.
The web proyect has a reference to the Java Application.
I have a Jar(of the java App),inside the Lib folder of the Web App.
The problem is ,each time i change someting in the Java appl ,i need to create
another jar and put it in the Lib folder of the Web App.
How do i configure Maven to do that?
Gracias!