Maven

Troubleshooting: Maven Dependency libraries not deployed in Eclipse IDE

A Java Web project may contain build dependencies to external libraries, specified inside the pom.xml file. In this tutorial, we will show you how to deploy all these libraries, along with the executable files of the project, using the Tomcat Server instance of the Eclipse IDE.

In this example, we use the following tools on a Windows 7 platform:

  • Apache Maven 3.1.1
  • Apache Tomcat 7
  • Eclipse Kepler Service Release 1
  • JDK 1.7

Please refer to this guide here, in order to verify that you know how to create a Java Web application project, using Apache Maven.

The dependencies of a Web project should be deployed inside the library folder of the Eclipse’s Tomcat Plugin, called WEB-INF/lib. However, the default .classpath file generated by Maven’s command

mvn eclipse:eclipse

is incomplete and must augmented with additional information. The default .classpath file is show below:

.classpath:

<?xml version="1.0" encoding="UTF-8"?>
<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/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

Also, if we take a closer look inside Tomcat’s Plugin folder, we will observe that the libraries are indeed not deployed. The default location of Tomcat’s folder is:

<Eclipse_workspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\

As shown below, there is no folder under the name “lib”, that contains all declared dependencies:

eclipse_metadata_plugins WM

1. Fix the problem through the Eclipse IDE

Inside the Eclipse IDE, we must locate our project. Then:

  • Right click on the project and select Properties.
  • Click on the Deployment Assembly in the left panel.
  • Click Add… on the upper right and then, select Archive via Path Variable.
  • Repeat Step c) for every dependency of the project.
  • Click Apply and finally, click OK.

If every step has been successfully executed, all dependencies of the project shall appear:

eclipse_deployment_assembly_WM

The updated .classpath file has been augmented with the attributes tag and has the following form:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.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"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

Important: You may need to delete the existing Tomcat Server instance from Eclipse’s Servers view and create a new Tomcat Server instance, in order for the applied changes to take effect.

2. Fix the problem through Terminal or Command Line

A simpler way to fix the aforementioned issue is by using the terminal (Linux or Mac) or the command prompt (Windows). We must navigate to the folder of our project and issue the following command:

mvn eclipse:eclipse -Dwtpversion=2.0

If the command is successfully executed, a new file called org.eclipse.wst.common.component will be created inside the .settings folder of the project, as shown below:

org.eclipse.wst.common.component:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="2.0">
<wb-module deploy-name="DynamicServlet">
<property name="context-root" value="DynamicServlet"/>
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
<wb-resource deploy-path="/" source-path="src/main/java"/>
<property name="java-output-path" value="/target/classes"/>
<dependent-module archiveName="javax.servlet-api-3.1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/var/M2_REPO/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar">
   <dependency-type>uses</dependency-type>
</dependent-module>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
</wb-module>
</project-modules>

3. Verify the deployment

If either of the proposed methods has been completed successfully, a new folder called lib will be created inside Tomcat’s Plugin folder, as shown below:

eclipse_metadata_plugins_updated WM

 
This was a tutorial on how to include and correctly deploy the dependencies of a Java Web project, using the Tomcat Server instance of the Eclipse IDE.

Sotirios-Efstathios Maneas

Sotirios-Efstathios (Stathis) Maneas is a PhD student at the Department of Computer Science at the University of Toronto. His main interests include distributed systems, storage systems, file systems, and operating systems.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button