Friday, April 8, 2011

[Maven] Integrate Maven with Eclipse


To integrate Maven with Eclipse, just follow the steps mentioned below and you're done!

Install Maven (3.0.3)

   1. Download Maven and unzip it.

   2. Create MAVEN_HOME System Variable.

   3. Add %MAVEN_HOME%\bin; to your System Path.

   4. On command prompt, type "mvn -version" to verify the installation, it will display following information

Apache Maven 3.0.3 (r1075438; 2011-02-28 22:31:09+0500)
Maven home: C:\Program Files\apache-maven-3.0.3\bin\..
Java version: 1.6.0_24, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_24\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

   5. On command prompt, type "mvn clean". This will download some jar files from Maven central repositor, followed by some BUILD FAILURE error indicating missing POM (pom.xml) file in current directory; so dont worry about it.

   6. Go to user home directory (for e.g. C:\Users\<username>), you'll find an .m2 folder with 'repository' subfolder. This is default local Maven repository location. As a result of "mvn clean" command, Maven downloaded maven-clean-plugin-2.4.1.jar file in it which you can see under C:\Users\<username>\.m2\repository\org\apache\maven\plugins\maven-clean-plugin\2.4.1 folder.

Now Maven is installed and ready to use with other projects.


Installing Maven Plugin for Eclipse

   1. After installing eclipse, install M2Eclipse in Eclipse using following update sites:

Maven Integration for Eclipse: http://m2eclipse.sonatype.org/sites/m2e/0.12.1.20110112-1712/
Maven Integration for Eclipse Update Site: http://m2eclipse.sonatype.org/update/

   2. As soon as you're done with all the steps followed by restart of Eclipse, you're now ready to Import your existing Maven projects in it.

   3. But before that, you might see a Maven Integration for Eclipse JDK Warning, stating to verify -vm option in eclipse.ini pointing to a JDK.

   4. To fix this, go to Eclipse installation directory (i.e. ECLIPSE_HOME), you'll see eclipse.ini file which contains command-line options that are added to the command line used to when Eclipse is started up.

   5. Add following lines to eclipse.ini before the -vmargs option, since everything after -vmargs is passed directly to the JVM.

-vm
C:\Java\JDK\1.5\bin\javaw.exe

Please note that the -vm option and its value (the path) must be on separate lines. Also, the value must be the full absolute path to the Java executable, not just to the JAVA_HOME directory. 

This will fix the JDK warning from Maven plugin, and now you can use Maven commands directly from Eclipse.