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 http://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 <wtpversion> setting. Even if you have the <wtpapplicationxml>true</wtpapplicationxml> element in your pom.xml, without the <wtpversion> tag the maven-eclipse-plugin will ignore all wtp project settings silently. So the solution was rather simple:
The short answer to this fun evening full of Googling and reading is: Add the <wtpversion> 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 <wtpapplicationxml> and <wtpversion> tags as shown at the bottom of this example pom file:
<project> <packaging>war</packaging> <dependencies> [...] </dependencies> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> <include>**/*.xsd</include> <include>**/*.wsdl</include> </includes> </resource> </resources> <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> </build> </project>
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:
mvn clean eclipse:eclipse
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.