Your Maven Java WEB project in Eclipse WTP

In our company, all Java projects are setup with Maven configuration so that after a "mvn eclipse:eclipse" any developer is generally good to go. One of these projects was a web project but would not transform into a WTP project. By running "mvn eclispe:eclipse" it became a Java project, but could not be added to a Server in Eclipse. It was not a WTP project.

I learned that the author of the project tried but never got the WTP plugin to work properly. Using the Google, I found more people who are having the same problem converting their existing Maven Java Web projects in Eclipse into a WTP project. There are even a few desperate articles describing how to edit your .project and .classpath files. Oh dear. This calls for an article on www.rolfje.com.

It all came down to the maven-eclipse-plugin which would just not configure my project properly. I soon learned that in their infinite wisdom, the development team decided that the maven-eclipse-plugin no longer uses a default value for the __ setting. Even if you have the _true_ element in your _pom.xml_, without the __ tag the maven-eclipse-plugin will ignore all wtp project settings silently. So the solution was rather simple:

**Short answer **The short answer to this fun evening full of Googling and reading is: Add the tag to your maven-eclipse-plugin configuration, run "mvn clean eclipse:eclipse" and refresh your project. That's it.

**The long version **For people who like to copy-paste (like me): Change your pom.xml file in the root of your project to include the and tags as shown at the bottom of this example pom file:

[sourcecode language="xml" toolbar="false" wraplines="true" padlinenumbers="true" autolinks="false" highlight="46,47"] war

[...] src/main/java **/*.xml **/*.xsd **/*.wsdl
<testResources>
  <testResource>
    <directory>src/test/java</directory>
    <includes>
      <include>**/*.xml</include>
    </includes>
  </testResource>
</testResources>

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.6</source>
      <target>1.6</target>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <configuration>
      <wtpapplicationxml>true</wtpapplicationxml>
      <wtpversion>2.0</wtpversion>
    </configuration>
  </plugin>
</plugins>
[/sourcecode]

Open a command prompt at the root of your project (where the_ pom.xml_ file is) and have maven re-fresh the project, like this:

[sourcecode light="true"] mvn clean eclipse:eclipse [/sourcecode]

Open eclipse, right click on the root of your project and select "refresh" (or press F5).

After you've done this, you should have "Web Project Settings" in the properties of the eclipse project. If you right-click on your defined servers in Eclipse, the project should show up in the "Add and Remove" dialog.

Have fun!