Troubleshooting: Maven – Tomcat deploys project web.xml to wrong folder in Eclipse
In this tutorial we will show you how to specify the correct deployment folder of the web.xml
file of a Maven based Web Java project.
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
By default, the Tomcat Server plugin of the Eclipse IDE deploys the web.xml
file to a wrong location, rendering the web application unable to run. The default deployment path is:
<Eclipse_workspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\<Project name>\WEB-INF\classes\WEB-INF\web.xml
while the correct deployment path is defined as:
<Eclipse_workspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\<Project name>\WEB-INF \web.xml
In order to deal with the aforementioned error, we must modify the default settings of our project and explicitly specify the deployment path of the Apache Tomcat. To achieve that, we must edit the following file:
<Eclipse_workspace>\<Project name>\.settings\org.eclipse.wst.common.component
As we can observe, the default deployment path is defined as
<wb-resource deploy-path="/" source-path="/WebContent"/>
We must change the source-path
attribute and make it point to src/main/webapp
. If all changes have been successfully applied, the org.eclipse.wst.common.component
file shall have the following form:
org.eclipse.wst.common.component:
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.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"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/> </wb-module> </project-modules>
This was a tutorial on how to deploy the web.xml
file of a Maven based Web Java project to the correct folder of Apache Tomcat.