Wednesday, May 21, 2008

Generation of Eclipse projects using maven

I believe that everyone who uses maven and eclipse is familiar with eclipse:eclipse goal. For these who are not familiar: get familiar with it as quick as you can! It does a very simple but powerful thing: generates eclipse projects for you with all the dependencies.

And here are some tips:

1. To generate new eclipse project from pom.xml, type "mvn eclipse:eclipse".

2. To generate new eclipse project with source attachments type: "mvn eclipse:eclipse -DdownloadSources=true"

3. To regenerate eclipse project close the project in eclipse and type "mvn eclipse:clean eclipse:eclipse". Add "-DdownloadSources=true", if you like to.

4. Now suppose you have hierarchy of projects. You may like to generate all projects with the proper dependencies between them or you may like to generate a project or two, which are dependent on the repository.
In the first case run "mvn eclipse:eclipse" using root pom.xml. In the second case run "mvn eclipse:eclipse" from the project's directory.

5. To use the projects in eclipse, you need to configure variable called M2_REPO which must point to your local repository. Maven can do it for you by running "mvn -Declipse.workspace= eclipse:add-maven-repo". Although I don't find this feature very useful, since you need to do it only once per workspace and it can be shortly done manually.

No comments: