How to add M2_REPO classpath variable to Eclipse IDE

Normally, when you use Maven command mvn eclipse:eclipse to convert existing Java project to support Eclipse project, Maven will create the entire dependency classpath by using the M2_REPO variable, which is not defined in Eclipse by default.

Nothing special, M2_REPO is just a normal “classpath variable” in Eclipse to find your local Maven repository.

Here, we show you two ways to add M2_REPO classpath variable into Eclipse IDE.

1. Add M2_REPO Manually

Define and add M2_REPO classpath variable manually into Eclipse IDE. Follow below steps :

  1. Eclipse IDE, menu bar
  2. Select Window > Preferences
  3. Select Java > Build Path > Classpath Variables
  4. Click on the new button > defined a new M2_REPO variable and point it to your local Maven repository
  5. Done.

2. Add M2_REPO Automatically – eclipse:configure-workspace

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

mvn -Declipse.workspace="your Eclipse Workspace" eclipse:configure-workspace

See an example :

C:\>mvn -Declipse.workspace="C:\Users\mkyong\workspace" eclipse:configure-workspace
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [eclipse:configure-workspace] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [eclipse:configure-workspace {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Apr 14 20:45:17 SGT 2011
[INFO] Final Memory: 9M/112M
[INFO] ------------------------------------------------------------------------


Verify M2_REPO is Added
Review classpath variable to verify that the M2_REPOis added into Eclipse IDE.

Add ME_REPO to Eclipse IDE

You need to add this M2_REPO classpath variable once only, and this variable is shared among all of your Eclipse’s workspace.

The old “eclipse:add-maven-repo” command is deprecated , and not working anymore. Uses “eclipse:configure-workspace” instead.


  1. Add Maven repo example
  2. Configure Maven workspace
Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.