Friday, March 18, 2011

Rough Steps to enable maven + eclipse + tomcat with existing maven project

this was my environment:

* eclipse version is helios j2ee
* tomcat should be installed locally somewhere.
* maven (mvn) is installed and available from the command line.
* install m2eclipse (maven integration for eclipse) plugin

1) clone git repository to a local directory. cd to directory and run: mvn eclipse:eclipse
2) open eclipse and create a new workspace (not the globalidm git directory)
3) file -> import -> general -> existing projects into workspace. choose the globaldm cloned directory
4) right-click web project, choose properties. click "Project Facets" and check the "Dynamic Web Module" box.
5) click servers tab. right click in pane, choose New. Define a new server.
6) right-click on server, choose "Add and Remove" and move your web project to the right to configure it.
7) now follow instructions here: http://www.devx.com/java/Article/36785/1763/page/2 starting with "Enable Maven" until you get to "Configuring J2EE Module Dependencies" (which if you can, great, but I didn't have a "J2EE Module Dependencies" option, so the following is the workaround)
8) right-click web project, choose properties. click "Deployment Assembly". Click "Add" button, "Java Build Path Entries", select all, finish.
9) use right-click project, Run-As -> maven build to build your project as a test. fix any problems until you can build clean.

Note: if you need to add/remove dependencies, open the pom.xml and choose 'dependencies' tab (below pom.xml editor pane). m2 makes it very easy to search, find and maintain dependencies. don't miss the 'dependency hierarchy' tab, too, very helpful. Once you make dependency changes, however, note that your classpath will not reflect those changes until you run: mvn eclipse:eclipse. After you do that, maven will regenerate the classpath file for eclipse based on the dependencies but note: you'll have to re-do step 8 ("Deployment Assembly"). Quite possibly, using a version number for WTP will fix this, but I haven't tried yet (http://maven.apache.org/plugins/maven-eclipse-plugin/wtp.html)

Also, for projects with dependency on submodules, you'll need to "mvn install" each project so that the jar is available to the local repository.

Tuesday, March 15, 2011

Integrating M2Eclipse with an existing Maven project

If you're importing an existing Maven project into Eclipse, you have to so some manual configuration to get both of them happy.  The problem is that Eclipse constructs a webapp directory structure a certain way while Maven has slightly different expectations.  You need to modify you classpath and build directives manually.

This was extremely helpful: 

http://www.devx.com/java/Article/36785/1763/page/2

It was especially relevant in the section toward the bottom called "Some Manual Tweaking of WTP Internals".