In previous article, we have integrated Apache Maven – a popular build tool with Eclipse IDE
By default, M2_REPO classpath variable doesn’t come added with Eclipse IDE in older versions
With newer versions like Kepler, Luna or Mars OR after integrating maven plugins (m2eclipse) with Eclipse IDE, M2_REPO classpath variable gets added –> pointing to default locations (for example c:\Users\<user_name>\.m2\repository) and this variable is non-modifiable –> means we can’t edit it to point to the correct local maven repository
Lets us concentrate on setting M2_REPO classpath variable and in the succeeding article we will see how can we edit this non-modifiable variable and correct it to point local maven repository
There are two ways
- Manual approach via Eclipse IDE
- Maven command approach
Way 1: Manual approach via Eclipse IDE
Step 1: Open Eclipse IDE –> Windows –> Preferences
Step 2: Go to Java –> Build Path –> Classpath Variables
Step 3: Click New –> Enter following details –> Click OK
Name: M2_REPO
Path: D:\M2_HOME\.m2\repository (pointing to local maven repository location)
Step 4: Done “M2_REPO” classpath variable added to Eclipse IDE successfully
That’s all !! completed walking to Way-1. Lets us move on to check the Way-2
Way 2: Maven command approach
Step 1: Run below maven cmd in Windows command prompt
Syntax:
mvn -Declipse.workspace="eclipse_workspace_location" eclipse:configure-workspace
Example:
mvn -Declipse.workspace="D:\WORKSPACE\TEST_WORKSPACE" eclipse:configure-workspace
Note: Before moving to Step 2 to verify, close eclipse IDE if it’s already opened and open again (restart required to take effects of new changes)
Step 2: Verify …..Whether M2_REPO classpath variable added or not –> pointing to correct local maven repository location
That’s pretty clear now, we can add M2_REPO classpath variable using mvn command
References
http://maven.apache.org/guides/mini/guide-ide-eclipse.html
http://maven.apache.org/guides/mini/guide-ide-eclipse.html#Maven_2_repository
Happy Coding !!
Happy Learning !!