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.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Riz
Guest
Riz

Thank you! This really saved me … after spending hours on various attempts, this one finally did it.

Harry
Guest
Harry

Great tutorials..
Can you add a tutorial with maven profiles… (like deploying into different regions)

ahmet kara
Guest
ahmet kara

Hi,
could you post an article about how to create a maven archetype from an existing maven project.

Thanks a lot…

trackback
Maven Tutorials | Tutorials

[…] Tomcat deploy Maven project web.xml to a wrong folder in Eclipse […]

trackback
How to convert Java web project to Maven project | Maven

[…] After the migration, you may find out Eclipse will deploy your “web.xml” file to a wrong folder during debugging session. This is cause by the Eclipse deployment setting. you have to update the Eclipse deployment setting file as well , check this. […]