Skip to content

www.rolfje.com

Your Maven Java WEB project in Eclipse WTP

Posted on 2011-01-29 By rolfje 12 Comments on 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 <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:

&lt;project&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;

  &lt;dependencies&gt;
    [...]
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;resources&gt;
      &lt;resource&gt;
        &lt;directory&gt;src/main/java&lt;/directory&gt;
        &lt;includes&gt;
          &lt;include&gt;**/*.xml&lt;/include&gt;
          &lt;include&gt;**/*.xsd&lt;/include&gt;
          &lt;include&gt;**/*.wsdl&lt;/include&gt;
        &lt;/includes&gt;
      &lt;/resource&gt;
    &lt;/resources&gt;

    &lt;testResources&gt;
      &lt;testResource&gt;
        &lt;directory&gt;src/test/java&lt;/directory&gt;
        &lt;includes&gt;
          &lt;include&gt;**/*.xml&lt;/include&gt;
        &lt;/includes&gt;
      &lt;/testResource&gt;
    &lt;/testResources&gt;

    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.6&lt;/source&gt;
          &lt;target&gt;1.6&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.1.1&lt;/version&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;wtpapplicationxml&gt;true&lt;/wtpapplicationxml&gt;
          &lt;wtpversion&gt;2.0&lt;/wtpversion&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;

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!

Software Tags:eclipse, Java, maven, programming, wtp

Post navigation

Previous Post: Why some App Store apps won’t install
Next Post: Changing the Order of your UnitTests

Comments (12) on “Your Maven Java WEB project in Eclipse WTP”

  1. harkje says:
    2011-02-15 at 12:59

    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….

    Reply
  2. Tim van der Leeuw says:
    2011-06-10 at 09:53

    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…

    Reply
  3. Pingback: Maven WEB project in Eclipse WTP - Maven Tutorial
  4. Anilkumar GT says:
    2011-07-07 at 15:26

    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

    Reply
    1. rolfje says:
      2011-07-07 at 20:01

      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.

      Reply
  5. Douglas says:
    2011-08-03 at 02:16

    Thanks for this tutorial.

    Reply
  6. Nacho says:
    2011-08-16 at 18:17

    Thanks a lot, worked like a charm 🙂

    Reply
  7. Pingback: Configure maven project with WTP Eclipse plugin « phuonghqh
    1. Rolf Gisler says:
      2012-09-27 at 15:15

      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

      Reply
      1. Erik Kerkhoven says:
        2012-10-15 at 22:45

        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

        Reply
  8. Erik Kerkhoven says:
    2012-10-15 at 22:51

    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.

    Reply
  9. Erik Kerkhoven says:
    2012-10-16 at 10:00

    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.

    Reply

Leave a Reply to Erik Kerkhoven Cancel reply

Your email address will not be published. Required fields are marked *

           

Recent Comments

  • rolfje on Methode Buijs uitgelegd
  • LinkedIn is at Peak Enshittifaction – Will Chatham's Blog on Linked-In not really Opt-in?
  • Hans j on 1N4148 diode as RF switch
  • Roaming Rhonda on DLNA on OSX, done right
  • Frans on How to fix a Krups XN2001 Nespresso machine

Tags

Anonimatron Apple backup design DIY DRM eclipse environment Fun gmail google hacking hamradio Hardware helicopter iphone ipod iTunes Java Keynote maven modelling motorcycle music news opinion oracle osx photo photography programming repair review security Software Steve Jobs T-Mobile technology Time Machine Ubuntu usability Utilities vacation windows Workshop

Categories

  • Apple (105)
  • Divorce (1)
  • Electronics (3)
  • Fun (57)
  • Games (7)
  • Hardware (72)
  • Microsoft (18)
  • Racing (14)
  • Software (134)
  • Uncategorized (65)
  • Workshop (20)

Archives

Copyright © 2025 www.rolfje.com.

Powered by PressBook WordPress theme