Sotirios-Efstathios Maneas

About Sotirios-Efstathios Maneas

Sotirios-Efstathios (Stathis) Maneas is a postgraduate student at the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. His main interests include distributed systems, web crawling, model checking, operating systems, programming languages and web applications.

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.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.
Examples Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Examples Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close