When you use Maven plug-in for Eclipse (Eclipse WTP) it generates you a project using predefined archetype but then Eclipse does not recognize this project as Web project and you loose the ability to debug it.
This is what you can do to fix it. First, we need to convert this project into Eclipse WTP web project.
This is .project file before modification
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>web</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.maven.ide.eclipse.maven2Builder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> <nature>org.maven.ide.eclipse.maven2Nature</nature> </natures> </projectDescription>
We need to add a new builder and a new nature to the project. You will need to insert this XML code into this file.
This will go under build spec section:
<buildCommand> <name>org.eclipse.wst.common.project.facet.core.builder</name> <arguments> </arguments> </buildCommand>
and this will go under natures:
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
This is .project file after modification:
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>web</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.maven.ide.eclipse.maven2Builder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.wst.common.project.facet.core.builder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> <nature>org.maven.ide.eclipse.maven2Nature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature> </natures> </projectDescription>
Now you need to go to project properties and select appropriate facets. To do that you need to right click on the project name and select Properties. On project Properties dialog you will need to select Project Facets.
On that screen you will need to select Dynamic Web Module, and appropriate version of Java for this module. For example if you select Dynamic Web Module version 2.5 you will need to have Java 5 or higher selected too.
Once you selected these facets and saved project project properties Eclipse will add new folder to your project called WebContent. This is the folder where Eclipse will store all the web files such as web.xml and JSPs.
Now you have a web project that will be recognized by Eclipse and you can add this project to your server.
The problem with this is that Maven does not know anything about this WebContent folder and won’t be able to build you project. You have two options: you can update the POM file to change the location of webapp folder, or you can update project settings to replace WebContent with /src/main/webapp.
This is what you need to do: open up org.eclipse.wst.common.component file under .settings folder. It would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="web">
<wb-resource deploy-path="/" source-path="/WebContent"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
<property name="context-root" value="web"/>
<property name="java-output-path" value="/web/target/classes"/>
</wb-module>
</project-modules>
Replace /WebContent with /src/main/webapp and save the file.
This is what updated file would look like:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="web">
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
<property name="context-root" value="web"/>
<property name="java-output-path" value="/web/target/classes"/>
</wb-module>
</project-modules>
Now you can delete WebContent folder and your project is fully configured with web support and can be debugged inside Eclipse and build by Maven.
- I am an IT professional with more than 12 years of experience in various software development areas, including system analysis, design and testing. I help my clients to convert business ideas into real-life solutions that make their businesses more profitable.







