M2E and WTP

When you use Maven on a Java web project, it would ideally be nice of course if this played along nicely with Eclipse WTP.

For simple projects, a <packaging>war</packaging> project with some <dependencies> to some normal (<packaging>jar</packaging>) artefacts, this seems to work kind of work nowadays (i.e. m2eclipse 0.10.2, WTP 3.3.3, Eclipse 3.6.1).

For more advanced projects using modularity to aggregate a web application e.g. via Maven WAR overlay, it doesn't seem to work (well/easily/reliably), see e.g. MNGECLIPSE-599 (note http://code.google.com/p/m2eclipse-wtp-ext/, never a good sign if somebody feels the need for something like this), and WTP integration related open issues in m2e.

My article Fully Classpath-based Web Apps in Eclipse based on an embedded Jetty Simple Server may be of interest to you if you have anything but a trivial application. If you aren't ready to give up on WTP and Tomcat yet ;), then read on.

Older blog posts often mention the maven-eclipse-plugin (with <wtpversion>...</wtpversion> or -Dwtpversion=R7) and mvn eclipse:eclipse, or mention the org.eclipse.jst.j2ee.LibCopyBuilder, but either do not seem to be needed anymore today.

So here is how to set it up (for simple projects) :

WTP & m2e collaborated, and the JAR files were copied somewhere under your workspace' .metadata\.plugins\org.eclipse.wst.server.core\...\wtpwebapps\mytestwebapp\WEB-INF\lib.

If you are having issues with this set-up, you may would like to check the Project Properties, Web Deployment Assembly settings.

Note that e.g. a Maven > Update Project Configuration will remove the attribute org.eclipse.jst.component.dependency from MAVEN2_CLASSPATH_CONTAINER again (in the current m2eclipse v0.10.2 at least), so careful.

The source code of the example project is attached below, and on https://github.com/vorburger/EclipseWebDevEnv/tree/master/m2e-and-wtp/.

References