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
1. Setting M2_REPO classpath variable in IDE :
There are two ways
- Manual approach via Eclipse IDE
- Maven command approach
1.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
1.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
2. Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
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 !!