M2Eclipse and WTP
WTP and M2Eclipse do not play very nicely together. We have identified 2 main problems:
- Converting Maven projects to WTP projects so that they can be auto-deployed to the servlet container.
- Multi-modules projects where the web project has dependencies on one or more of the other modules and you want to be able to debug freely into any module. In this case if you allow a project per module, the other modules never seem to get deployed to the web project.
I will deal with issue 1 first. Most of this solution came from a posting on the eclipse.webtools newsgroup, however it is quite incomplete with respect to Maven projects:
- Open .project file for the project to be converted to web project.
- Insert the following to natures element:
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> - Open the properties for the project and go to the section for Project Facets
- Add Java and Dynamic Web Module facets to the project. (I forgot the Java facet first time around and had a lot of confusion until I worked it out)
The above will work for a non-maven project the rest you will need if you are using m2eclipse:
Open the .classpath file and add the following:
<classpathentry exported=”true” kind=”con” path=”org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER”>
<attributes>
<attribute name=”org.eclipse.jst.component.dependency” value=”/WEB-INF/lib”/>
</attributes>
</classpathentry>
Open the org.eclipse.wst.common.component file in the .settings folder of your project and add this line inside the wb-resource block:<wb-resource deploy-path=”/” source-path=”<nested module name if you have one>/src/main/webapp”/>
Issue 2 is really annoying to me since most of our applications use multiple modules to decouple the services from the way they are exposed, ie. via a Java MVC framework, Web Services or via BlazeDs to a Flex RIA. Having this limitation forces us to have a single eclipse project for the services and the web tier or transport tier. This can have the effect of hiding coupling between your services and the web or transport tier.
Nevertheless it is a reality that has to be dealt with right now. You can manage it very easily in IntelliJ, however, even there I can, as yet, find no way to tell the editor that the service tier jar source code is actually in the editor so that I can set break points. Probably this could be dealt with but I was reluctant to spend time on it when I know our management would flip if I suggested paying for all developers to have IntelliJ licenses
Okay, so the way to solve this problem with m2eclipse is to have the service or core application and the web server application as a single project with multiple maven modules. This sucks for a couple of reasons. The first is that if you have decomposed your application into more that 2 modules it is very hard to manage all the source folders in eclipse. The second reason I mentioned above, this approach will actually have eclipse compiling all classes into the one class folder and deploying that to your web server once you set WTP up. I have seen a number of instances where this effectively makes decomposing your application into multiple modules a waste of time or worse since it gives you the impression that you are enforcing a decoupling when in fact you are not.
If you use this approach then the instructions above still apply in terms of setting up WTP once you have created your multi-module project. In the last step you will need to prepend the web server module name to src/main/webapp (the angle brackets in the description above show exaclty where this goes).
I hope this helps someone, at the very least it will help me the next time I have to deal with this.
January 9th, 2009 at 2:34 am
Can you please elaborate on what do you mean that m2eclipse and WTP do not play very nicely together? Do you have latest dev build installed with Maven integration for WTP feature? That feature should take care of both of your scenarios and we have few example projects that demonstrate that. There is initial documentation and mini howto on the project wiki:
http://docs.codehaus.org/display/M2ECLIPSE/Integration+with+WTP
http://docs.codehaus.org/display/M2ECLIPSE/WTP+mini+howto
If you have issues with WTP integration, please report bugs to the project. The following wiki page have few tips how to make it efficient:
http://docs.codehaus.org/display/M2ECLIPSE/Reporting+Issues
March 5th, 2010 at 2:15 am
I has the same issue.
Just install the “Maven Integration for WTP” from the m2eclipse Extras Update Site: http://m2eclipse.sonatype.org/sites/m2e-extras and everything is fine.
April 19th, 2010 at 8:55 am
@Pierre — Thanks a million. I “Upgraded” to the latest m2eclipse plugin to fix some bugs and this one really screwed me up for a bit as my WTP functionality seemed to have disappeared for maven. I’m glad I stumbled across your post.