Maven dependency libraries not deploy in Eclipse IDE

Problem

By default, while starting the Tomcat server instance in Eclipse, the project’s dependency libraries will not deploy to the Eclipse’s Tomcat plugin library folder ‘WEB-INF/lib’ correctly. See this “.classpath” file, that is generated by Maven “mvn eclipse:eclipse” command.


<classpath>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>

  <classpathentry kind="var" 
    path="M2_REPO/org/apache/struts/struts-core/1.3.10/struts-core-1.3.10.jar" />
  <classpathentry kind="var" 
    path="M2_REPO/org/apache/struts/struts-taglib/1.3.10/struts-taglib-1.3.10.jar"/>

  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

See the following Tomcat plugin folder, obviously, the dependency libraries are not deploy.
$workspace_folder\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\StrutsExample

maven-eclipse-library-error1

Solution

As i know, there are two solutions :

1. Java EE dependencies module

In Eclipse IDE, right click on the project, click properties and select the Java EE module dependencies and check all the project dependency libraries.

maven-eclipse-library-solution1

This will update the Eclipse’s classpath (.classpath) by adding corresponds “attributes” tag


<classpath>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="var" 
    path="M2_REPO/org/apache/struts/struts-core/1.3.10/struts-core-1.3.10.jar" >
    <attributes>
      <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
  </classpathentry>
  <classpathentry kind="var" 
    path="M2_REPO/org/apache/struts/struts-taglib/1.3.10/struts-taglib-1.3.10.jar" >
    <attributes>
     <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
  </classpathentry>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

See the Tomcat plugin folder again, all dependency libraries are deployed to the “WEB-INF/lib” folder correctly.
$workspace_folder\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\StrutsExample

Note
In Eclipse, you may need to delete the existing Tomcat server instant in the server tab, and create a new tomcat server instance to take effect.

2. WTP Support

Alternatively, you can issue the following command to make Maven support Eclipse WTP tool.


mvn eclipse:eclipse -Dwtpversion=2.0

The above command will generate a new file named “org.eclipse.wst.common.component” under project’s “.settings” folder.


<project-modules id="moduleCoreId" project-version="2.0">
  <wb-module deploy-name="StrutsExample">
    <property name="context-root" value="StrutsExample"/>
    <wb-resource deploy-path="/" source-path="src/main/webapp"/>
    <property name="java-output-path" value="/target/classes"/>
    <dependent-module archiveName="struts-core-1.3.10.jar" deploy-path="/WEB-INF/lib"
handle="module:/classpath/var/M2_REPO/org/apache/struts/struts-core/1.3.10/struts-core-1.3.10.jar">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    <dependent-module archiveName="struts-taglib-1.3.10.jar" deploy-path="/WEB-INF/lib"
handle="module:/classpath/var/M2_REPO/org/apache/struts/struts-taglib/1.3.10/struts-taglib-1.3.10.jar">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
  </wb-module>
</project-modules>

Now, start the server again, all dependency libraries will be deployed to the “WEB-INF/lib” folder automatically.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
19 Comment threads
3 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
17 Comment authors
Snehal MasneKaran Handasextoy shop malaysiaSivaWalid Recent comment authors
newest oldest most voted
Snehal Masne
Guest
Snehal Masne

I’ve stuck into this blocker for an entire week suspecting that there is a problem with my GWT for Eclipse plugin… but answer is so simple!

Karan Handa
Guest
Karan Handa

Mr yong,
i was trying this example and as a part of it i downloaded your sample project above above and imported it to my workspace also downloaded struts 1.3.all and extracted it made a user library out of it and add to deployment assembly(very sure that struts-taglib.jar was added).But when i run the project i get the following error message.
HTTP Status 500 – javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: “helloWorldForm” in any scope

Siva
Guest
Siva

Thanks for solution…. After this i got another error.. got it solved by following the steps in http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14527523

Thanks again.

Siva

Walid
Guest
Walid

Installing “Maven Integration for Eclipse WTP” from Eclipse Marketplace solved that for me.

I think that is a better solution as, with that plugin, libraries deployed to WEB-INF/lib will be updated when maven dependencies are updated/added/deleted.

trackback
How to use mkyong tutorial

[…] Maven dependency libraries not deploy correctly Tags : mkyong tutorials mkyong Founder and Chief Editor of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. […]

trackback
Maven Blues 2 « thatfrontend

[…] eclipse:eclipse¬†-Dwtpversion=2.0 A full reference here in mkyong’s¬†blog. Share this:TwitterFacebookLike this:LikeBe the first to like […]

reyand
Guest
reyand

Thank’s a lot for these solutions!
The 2nd solution may be is not good, because it differs from the original view (Libraries section looks different, and root directory for the project become webapp instead of WebContent). May be it’s ok, but anyway. So 1st is better for me.
I tried a new Eclipse Juno, WTP 3.4.0 and m2eclipse 1.1.1 – the 1st solution worked, but there are some light differences:
1) “Java EE module dependencies” is called “Deployment Assembly” now.
2) U have to choose “Maven Dependencies” in the “Add” dialog, after choosing “Java Build Path Entries”, instead of choosing all libraries independently.

ferhat
Guest
ferhat

Thank you very much. Alternative 2 worked for me.

Satya
Guest
Satya

Thanks so much , Your posted ended my two struggle on the issue

Mansour
Guest
Mansour

Hello :),

Thanks, very much for this work. It’s very helpful.

Best regards.
Mansour.

Gianluca
Guest
Gianluca

Thanks you saved me from insanity ……
I spent a week thinking of having done something wrong in my project ….

winnytoo
Guest
winnytoo

thanks a lot, a lot a lot!!! – you saved me! I’ve stuck into this blocker for an entire week suspecting that there is a problem with my GWT for Eclipse plugin… but answer is so simple! you are great, Man!

Gianluca
Guest
Gianluca

I also had the same problem ….
very very annoying

Luis
Guest
Luis

Thanks for the advice. For Eclipse Helios the option is “Deployment Assembly” in the project properties window. Then click Add button and next select Java Build Path Entries, then select Maven dependencies.

p00m
Guest
p00m

WOOT! Thanks for this!

Vinidog
Guest
Vinidog

Nice, nice, nice…
Tks a lot!!!

;-)

trackback
Eclipse : Web Deployment Assembly & Maven dependencies issue
Lukas (not Podolsky)
Guest
Lukas (not Podolsky)

I was looking for a solution to this problem and I could not find. And then you appeared under the following key words in Google:
“Eclipse tomcat deploy jar repository dependencies.”
Thank you very much, my friend. Postulate for president, man.

Adrian
Guest
Adrian

Thanks so much. I was stumped by this for ages until I came across this site.

trackback
Struts Hello World Example | struts

[…] Maven dependency libraries not deploy in Eclipse IDE […]

sextoy shop malaysia
Guest
sextoy shop malaysia

I was extremely pleased to find this site. I wanted to thank you for this great examine!! I definitely enjoying every amount of it and I have you bookmarked to view new stuff you publish.