HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Maven / M2_REPO – Change maven repository location in eclipse

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 !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.

Share this:

  • Twitter
  • Facebook
  • LinkedIn
  • Reddit

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. Rajendra Joshi

    January 8, 2013

    changed facet correctly, but to create web application from scratch mvn archetype:generate
    is stopping at number 242 :242 which creates, not a simple quick start web project but plugin project.
    which does not takes dependencies in pom file .
    so why mvn behavior is correct ?as it has so many options up till 710 , so what do ?

    • Lokesh Gupta

      January 8, 2013

      You must be having another maven version. Mine is 3.0.4. So, this list can differ.
      Filter for archetype quickstart like in below post.

      https://howtodoinjava.com/maven/create-a-simple-java-project-using-maven/

  2. Rajendra Joshi

    January 7, 2013

    I don’t have Modify Project option in projects facets page
    what to do?

    • Lokesh Gupta

      January 7, 2013

      Follow: http://help.eclipse.org/kepler/index.jsp?noscript=1

  3. Rajendra Joshi

    January 7, 2013

    yes I have added the repository but demoWebApplication gives folloing error
    when I changed java compiler from 1.7 to 1.6 ,even for java 1.7 this error was there
    Description Resource Path Location Type

    Java compiler level does not match the version of the installed Java project facet. demoWebApplication Unknown Faceted Project Problem (Java Version Mismatch)

    and when I create myfirstServlet and try to run it ,it gives
    HTTP 404 error-requested re source not available

    Pl give the remedy

    • Lokesh Gupta

      January 7, 2013

      Refer to following link for changing project facets correctly. Correct the JRE version here installed in your system.

      http://help.eclipse.org/kepler/index.jsp?noscript=1

Comments are closed on this article!

Search Tutorials

Maven Tutorial

  • Maven – Installation
  • Maven – Settings
  • Maven – Dependency Mgmt
  • Maven – Dependency Scopes
  • Maven – POM
  • Maven – Parent POM
  • Maven – Repositories
  • Maven – Local Repo Path
  • Maven – M2_REPO
  • Maven – Network Proxy
  • Maven – Enforce Java Versions
  • Maven – Simple Java Project
  • Maven – Web Project
  • Maven – Multi-module Project 1
  • Maven – Multi-module Project 2
  • Maven – Java Source Folders
  • Maven – BOM [Bill Of Materials]
  • Maven – Import Remote Catalogs
  • Maven – Create Custom Archetype
  • Maven – Compiler Level Mismatch
  • Maven – Ant Build
  • Maven – IntelliJ
  • Maven – JSTL Support
  • Maven – Tomcat Plugin
  • Maven – Uber Jar for Spring Boot
  • Maven – Shade Plugin
  • Maven – Remove corrupt jars

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Java 15 New Features
  • Sealed Classes and Interfaces
  • EdDSA (Ed25519 / Ed448)