Maven Generated Eclipse Project with WTP

To create an Eclipse project with Web Tools Platform (WTP) support, run the following command.

mvn eclipse:eclipse -Dwtpversion=2.0

Maven as Eclipse Dynamic Web Module

This quick tutorial will show you how to create a Maven project with a Dynamic Web Module facet. It uses m2e to generate the Maven project.

1. Run Eclipse and switch to the Java EE perspective.

2. Create a new Maven project. Pick the spring-mvc-jpa-archetype to get a fully configured Spring 3 MVC application.


3. If you don’t have a configured Eclipse Server, add one now. Here we will register a new Tomcat 7 server. Open the Servers view, right click -> New -> Server.

4. Hit next and enter the Tomcat installation directory.

When you hit next, notice you will not see any available resources that you can move to the server.

We still have to configure our new Maven project to become a Dynamic Web Module. This is our next step. Hit Finish to complete the new Server setup.

5. Now right click on the project and click Properties. Go to Project Facets.

Click on “Convert to faceted form” and pick “Dynamic Web Module” version 2.5. Picking version 2.5 makes it compatible with older web containers. Click “Further configuration available”, enter “srcmainwebapp” for the content directory, and hit OK.

6. Now to make the Maven dependencies available to the Dynamic Web Module, go to Project Properties again and click on Deployment Assembly. Click Add… and pick “Java Build Path Entries”. Hit next and pick Maven Dependencies.


7. Our project is now fully configured. To test, go to the Servers view, right click on the Tomcat Server and hit “Add and Remove…”. Pick mavenweb from the available resources and add it to the Server.

Start the server and go to http://localhost:8080/mavenweb. You should see

Now you have a Maven project fully configured as a Dynamic Web Module.

If you want to create the Maven project using mvn eclipse:eclipse, you have to configure the wtpversion.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-eclipse-plugin</artifactId>
	<version>2.8</version>
	<configuration>
		<wtpversion>2.0</wtpversion>
	</configuration>
</plugin>

M2Eclipse (m2e) Support for Maven Eclipse Plugin Projects

If you have a Maven based Eclipse project that you generated using mvn eclipse:eclipse, you’ll notice you won’t be able to use M2Eclipse (m2e) with it. If you look at the Eclipse .project file, you’ll see this comment.

NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.

Here’s how you can convert your Maven Eclipse Plugin project to m2e. First add the M2Eclipse builder under the buildSpec tag, and the M2Eclipse nature under the natures tag, both inside the .project file.

...
<buildCommand>
  <name>org.eclipse.m2e.core.maven2Builder</name>
</buildCommand>
...
<nature>org.eclipse.m2e.core.maven2Nature</nature>

Next step is to replace all the M2_REPO libraries in the .classpath file with the M2Eclipse classpath container.

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>

Refresh your Eclipse project. Right click on the project in Project Explorer View and you should now see the Maven option.