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 <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:
Short answer
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.
Have fun!
Or you try Netbeans or IntelliJ; then Maven integration “just works”. As an added bonus you do not have to insert IDE specific configuration in your IDE independent Maven pom. 🙂
Incredible how bad Maven support is the most popular/used IDE….
Yes, absolutely incredible! It’s what made me freak out with Eclipse in the first place several years ago (along with other issues, but this was among the top problems) and eventually settle on NetBeans…
I agree it can be frustrating to get this integration working…. later on i found out this command and note no need for any plugin related configuration changes …. just run the following command:
mvn -Dwtpversion=2.0 eclipse:eclipse
instead of just mvn eclipse:eclipse
Yes I found that too, before writing this post. It’s effectively doing the same thing, but now everybody in your team must remember to type that each time and without errors. The whole point of Maven is to have a painless, quick and easy setup.
Doing it this way will enable you to say “just check out and run mvn eclipse, and you’re done”. Your team will thank you for effort spent on getting this out of their way.
Thanks for this tutorial.
Thanks a lot, worked like a charm 🙂
I tried it with the Juno release of eclipse and receive an error when importing existing maven projects:
An internal error occurred during: “Updating Maven Project”.
Unsupported IClasspathEntry kind=4
That seems to be caused by the fact that the version of m2e plugin is too low. Rolfje will lauch again because that plugin came shipped with Juno… should be at least 1.1.0. I did:
1. remove project from eclipse
2. delete .classpath
3. import project again
See: http://stackoverflow.com/questions/10564684/how-to-fix-error-updating-maven-project-unsupported-iclasspathentry-kind-4
Rolfje it is written clearly on the Maven WTP support page:
“Note that in the 2.0 version of the plugin the default was R7 and WTP configuration was always generated. Now that different incompatible versions are out the default is to not to generate WTP configuration if the user doesn’t specify the desired version.”
See: http://maven.apache.org/plugins/maven-eclipse-plugin/wtp.html
What’s the problem? Just joking!
I think the difference with for example IDEA is that Eclipse is a flexible plugin platform. Plugins come and go, and it all has to work together.
Thanks for the blog! very usefull because this setup stuff I am doing only once in a while and forget easily.
I think that I do not agree with the opinion that Maven must be IDE independent. Maven offers the possibilty to configure plugins. Several tools can be plugged in, ranging from code compliance to JAXB. All those tools are part of the development environment of an engineer, The Maven plugins are by defintion not (I)DE independent.