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.