Eclipse WTP has this nice feature where it allows you to deploy, run and debug Web Applications from the IDE. You start by going to the Server View, adding the target server (like Apache Tomcat in our case) and then adding the Web Project to the server. This is how the view looks like:

But I have often faced this problem: when I run mvn eclipse:eclipse on a Maven Web Project to convert it to an Eclipse project, it is not recognised as a Web Project by Eclipse. When I right-click on the server and select Add Remove Projects, it does not appear in the option box. But to me mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true is indispensable as it downloads and links all the sources and JavaDocs, which comes very handy. On the other hand if I cannot add my project as a Web Project in Eclipse, running and debugging becomes a big issue. So how do I reconcile these two?
Solution 1: Specify the WTP Version
While running mvn eclipse:eclipse, specify the WTP Version by passing the -Dwtpversion=2.0 argument. The command looks like:
mvn eclipse:clean eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true -Dwtpversion=2.0
Note that as of this writing, the supported versions of WTP are 1.0, 1.5, 2.0 and R7.
Solution 2: Convert it to a Facted Project
Right click on the project, go to Properties, then select Project Facets.

Another dialog appears having the available facets.

Select Dynamic Web Module.
Solution 3: Manual editing
I like this best as it gives lot of flexibility around configuration. First you need to modify the .project file as shown:
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>MyWebProject</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.wst.jsdt.core.javascriptValidator</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.wst.common.project.facet.core.builder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.wst.validation.validationbuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature> </natures> </projectDescription>
Then, inside the .settings directory, you need to create two files called org.eclipse.wst.common.component and org.eclipse.wst.common.project.facet.core.xml.
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="MyWebProject"> <wb-resource deploy-path="/" source-path="/src/main/webapp"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <property name="context-root" value="MyWebProject"/> <property name="java-output-path" value="/MyWebProject/build/classes"/> </wb-module> </project-modules>
org.eclipse.wst.common.project.facet.core.xml
<?xml version="1.0" encoding="UTF-8"?> <faceted-project> <runtime name="Apache Tomcat v7.0"/> <fixed facet="jst.web"/> <fixed facet="wst.jsdt.web"/> <fixed facet="java"/> <installed facet="java" version="1.6"/> <installed facet="jst.web" version="3.0"/> <installed facet="wst.jsdt.web" version="1.0"/> </faceted-project>
Thanks, I was aware of the Maven approach, didn’t know about Facted project. Looks like you saved me a lot of time and taught me something new - thanks!
Regards,
Jan
Comment by Jan — October 27, 2010 @ 12:13
I created a project with Maven and then tried to make that a web project in Eclipse. After running the maven command mentioned here, the project become an eclipse project but not a web project.
I needed to change one thing in the generated pom.xml file by maven,
jar
to
war
and then everything was smooth.
Comment by Dyutiman — December 7, 2010 @ 19:22