M2_REPO – Change maven repository location in eclipse

Maven dependencies can be read from Eclipse IDE which maven exposes through M2_REPO classpath variable. m2_repo points to maven’s local repository location in workspace.

m2_repo class variable must be added to eclipse’s class path variable on build path before using maven’s dependencies.

1. Manually change maven repository location in Eclipse

1.1. Navigate to Windows > Preferences

eclipse-preferences-8945146

1.2. Navigate to Java > Build path > Classpath Variables

classpath_variables_for_projects-4687955

1.3. Define new classpath variable “M2_REPO”

Create new variable M2_REPO and point it to maven local repository location.

add_maven_repository-7353199

1.4. Verify that variable has been added

m2_repo_variable_added-6274010

2. Update M2_REPO from command line – eclipse:configure-workspace

Alternatively, you can define and add M2_REPO via Maven command "eclipse:configure-workspace".

For example this is the output of command in my system.

Microsoft Windows [Version 10.0.17134.228]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Lokesh>mvn -Declipse.workspace="E:\devsetup\workspace" eclipse:configure-workspace
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-eclipse-plugin:2.10:configure-workspace (default-cli) @ standalone-pom ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.815 s
[INFO] Finished at: 2018-09-09T14:50:20+05:30
[INFO] ------------------------------------------------------------------------
Add m2_repo from command prompt
Add m2_repo from command prompt

Happy Learning !!

Comments

Subscribe
Notify of
guest
6 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode