Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unbound classpath variable

When rebuilding my project with Maven I sometimes get hundreds of

'unbound classpath variable M2_REPO/etc/..'

in my eclipse errors, most of the time when I rebuild again it goes away but on this occasion its cursed me enough to stick around.

When actually going through the file system, the jars it details that are not there are actually there. Eclipse is just not seeing them for some reason. My m2_repo is correctly referenced in my preferences->java->classpathvariables section and my environmental variables are likewise properly set.

Any ideas for me folks?

like image 487
DasBooten Avatar asked Apr 10 '15 11:04

DasBooten


3 Answers

If you already did several times STEP 1, go to STEP 2

STEP 1
Try deleting and redefining env vars:

  • Open the Eclipse Preferences [Window - Preferences]
  • Go to [Java - Build Path - Classpath Variables]
  • Click New and set its name as M2_REPO
  • Click Folder and select your Maven repository folder. For example, my repository folder is C:/Users/user/.m2/repository
  • 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


STEP 2
If your build path is correctly defined, check Maven settings.xml:

Window --> Preferences --> Maven ---> User Settings

If not, set it there and change localRepository path in settings tag inside settings.xml. Normally you will find settings.xml in .m2 folder under the user folder (for eg. C:\Documents and Settings\userName.m2).

like image 114
Jordi Castilla Avatar answered Nov 17 '22 21:11

Jordi Castilla


Well, I tried the steps in @Jordi's answer. But those didn't make any difference. And I tried some ritualistic things in eclipse such as:

  • closing the project and opening it
  • restarting the IDE
  • cleaning and rebuilding etc...

with no success.

Then strange thing happened when I changed the Java complience level to 1.8 and revert it back to 1.6. It worked! All unbound classpath variable errors are gone now.

like image 24
Zolbayar Avatar answered Nov 17 '22 23:11

Zolbayar


Update Project worked for me :

Step 1 : Select Project Folder

Select the project folder that is giving the error.

Step 2 : Update Maven Project

Alt + F5 shortcut OR right-click >> Maven >> Update Project.

Step 3 : Finalize

Click OK and let it update.

The errors should disappear after that.

Good Luck

like image 1
Aakash Avatar answered Nov 17 '22 21:11

Aakash