Tomcat deploy Maven project web.xml to a wrong folder in Eclipse
Problem
During the Eclipse debugging session, the “web.xml” will always deploy to a wrong folder. It’s always cause by manual migrated or converted a Java web project to Maven’s project.
See the Eclipse’s workspace folder structure, Tomcat in Eclipse is deploy “web.xml” to a wrong folder, and causing the entire web application fail to run.
E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\
wtpwebapps\serlvetdemo\WEB-INF\classes\WEB-INF\web.xml
The correct “web.xml” location should be located at
E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\
wtpwebapps\serlvetdemo\WEB-INF\web.xml
Solution
Actually there is a setting file in Eclipse to control the deployment path in Tomcat, named “org.eclipse.wst.common.component“.
<!-- This is org.eclipse.wst.common.component original content -->
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="serlvetdemo">
<wb-resource deploy-path="/" source-path="/WebContent"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<property name="java-output-path"/>
<property name="context-root" value="servletdemo"/>
</wb-module>
</project-modules>
The deployment path is wrong, “/WebContent” is no longer required in Maven’s project, replace it with “src/main/webapp” as following
<!-- This is org.eclipse.wst.common.component modified content -->
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="serlvetdemo">
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<property name="java-output-path"/>
<property name="context-root" value="servletdemo"/>
</wb-module>
</project-modules>
Done, Eclipse and Tomcat plugin are working properly and deploy the “web.xml” file to a correct location now.
Thoughts….
This is cause by the manual migration or convert a Java web project to Maven’s project, hope Maven can come out the migration tool in future.
Thank you! This really saved me … after spending hours on various attempts, this one finally did it.
Great tutorials..
Can you add a tutorial with maven profiles… (like deploying into different regions)
Hi,
could you post an article about how to create a maven archetype from an existing maven project.
Thanks a lot…
Sorry, what you mean by create a “maven archetype from an existing maven project” ? Mind to elaborate more?