Wednesday, March 14, 2012

Maven - eclipse project

Any Maven project can readily generate an Eclipse project with the command:
> mvn eclipse:eclipse

Try it for the HelloWorldJARArch project:
(you will need to cd to the HelloWorldJARArch directory)
 C:\Users\mlavannis\workspace-confucius\HelloWorldJARArch>mvn eclipse:eclipse  
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My first Maven project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.9:eclipse (default-cli) @ HelloWorldJARArch >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.9:eclipse (default-cli) @ HelloWorldJARArch <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.9:eclipse (default-cli) @ HelloWorldJARArch ---
[INFO] Using Eclipse Workspace: C:\Users\mlavannis\workspace-confucius
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] File C:\Users\mlavannis\workspace-confucius\HelloWorldJARArch\.project already exists.
Additional settings will be preserved, run mvn eclipse:clean if you want old settings to be removed.
[INFO] Wrote Eclipse project for "HelloWorldJARArch" to C:\Users\mlavannis\workspace-confucius\HelloWorldJARArch.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.036s
[INFO] Finished at: Wed Mar 14 21:40:16 EDT 2012
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
C:\Users\mlavannis\workspace-confucius\HelloWorldJARArch>

Maven will download the necessary libraries before building the Eclipse project.

Note:
There is a difference between a Maven and an Eclipse project.

Maven projects contain a pom.xml which tell Maven how to build your project.

Eclipse projects contain a .project file which tell Eclipse how to open your project and provide IDE support.

Needless to say, when a project contains both, a pom.xml and a .project file, it can be opened in Eclipse and built by Maven.

The two co-exist without any problems.

To open your HelloWorldJARArch project in Eclipse, go to:
File-->Import-->General-->Existing Projects into Workspace

Browse to the workspace-confucius folder.

Select the HelloWorldJARArch project and click Finish.

Your project is now ready to be worked on in Eclipse, and it can be built with Maven.