Unbound Classpath Variable M2_REPO in Eclipse

So here’s the situation, I just checked out new project from SVN (Subversion) and when I open up my Eclipse, there are lots of Java Build Path Problems. The error says something like this:

Unbound classpath variable: 'M2_REPO/...'

Unbound classpath variable M2_REPO

Unbound classpath variable M2_REPO


If you get those errors, it means you haven’t set M2_REPO variable in your Eclipse.

How to Fix Unbound Classpath Variable Error in Eclipse?

  1. Open the Eclipse Preferences [Window - Preferences]
  2. Go to [Java - Build Path - Classpath Variables]
  3. Click New and set its name as M2_REPO
  4. Click Folder and select your Maven repository folder. For example, my repository folder is C:/Users/Firman El Hakim/.m2/repository
  5. Add M2_REPO Variable

    Add M2_REPO Variable

  6. Done. Rebuild the Project.

Beside from inside of Eclipse, you can also add the M2_REPO variable from command line using this Maven command:

mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
No Responses