Reputation: 329
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?
Upvotes: 18
Views: 42149
Reputation: 76
M2_REPO
should point to ~/.m2/repository
(in Eclpise Windows > Preferences > Java > Build Path > Classpath Variables > New...
)
maven command is:
mvn -Declipse.workspace="path-to-eclipse-workspace" eclipse:configure-workspace
(NOT eclipse:add-maven-repo
as sugested in the first answer)
Upvotes: 0
Reputation: 1
I have tried all the things above but none of them works for me. Here is the solution which works for me;
right click to project>>Build Path> Configure Build Path>Libraries
You are gonna see all jars that you see in problems (M2_REPO....)
>>>Select these jars>>> Remove>>Apply and Close
exclamation mark disappears and all errors gone
Note: before that I also did mvn clean install, update project when did not help I tried this
Hope helps for you...
Upvotes: 0
Reputation: 981
I tried setting the M2_REPO variable several times, but finally the only thing helped was starting Eclipse with -clean parameter.
Upvotes: 0
Reputation: 23737
Update Project
worked for me :Select the project folder that is giving the error.
Alt + F5
shortcut OR right-click >> Maven >> Update Project
.
Click OK
and let it update.
The errors should disappear after that.
Good Luck
Upvotes: 1
Reputation: 603
Mars.2 was having this problem for me. Tried all these suggestions, then deleted the ~/.m2/repository/.metadata folder, restarted eclipse, and M2_REPO was there.
Got there by looking at Maven - User Settings, but there's no settings.xml, but there was a .metadata folder, which if you drill down there's a jdt file with the eclipse .m2 repository location. Figured it wasn't doing any good, so I deleted it. After restarting eclipse and M2_REPO is configured, the ~/.m2/repository/.metadata folder is still deleted. Must have conflicted with something else in the workspace. Don't know how it got there in the first place.
Upvotes: 0
Reputation: 936
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:
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.
Upvotes: 10
Reputation: 26961
If you already did several times STEP 1, go to STEP 2
STEP 1
Try deleting and redefining env vars:
C:/Users/user/.m2/repository
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).
Upvotes: 43
Reputation: 103
I have seen this issue before more than once and I don't use the maven plugin so I dont have windows -> Preferences->Maven.
To resolve this 'unbound classpath variable M2_REPO/etc/..
' though you have M2_REPO variable setup issue -> Rename M2_REPO variable to something else (M2_REPO2 for eg) and then correct it back to M2_REPO and this issue goes away.
Upvotes: 0