Monday, December 12, 2011

Creating an Eclipse Dynamic War project from a Maven project is easy

The Maven Eclipse plugin is a great tool that lets you create an Eclipse project from a Maven project with just the mvn eclipse:eclipse command.  It always seems to work great on my big projects,probably  because someone has already done the configuration required to get the right information generated into .project and .classpath.  I've always struggled to make it work in a small demonstration or test project.  The maven constructed Eclipse project is never configured right and I can't run the war on my local Servlet container.

Eclipse supports web files through the Eclipse Web Tools Project (WTP) project and through the Dynamic Web Facet when facets are enabled.  The Dynamic Web Facet is either missing or mis-configured after the mvn eclipse:eclipse command.

You must tell the Maven Eclipse Plugin (not to be confused with m2e) to use WTP when building the Eclipse project. The simplest command is:

      mvn -Dwtpversion=2.0 eclipse:eclipse

You must use the correct wtpversion for your eclipse installation. The latest version, as of December 2011, is 2.0. You can find more information about the maven eclipse plugin configuration at http://maven.apache.org/plugins/maven-eclipse-plugin/wtp.html