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.

Tags :
Founder of Mkyong.com and HostingCompass.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 making a donation to this charity, thanks.

Related Posts

Popular Posts