简体   繁体   中英

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?

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).

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.

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

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.

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.

我尝试多次设置M2_REPO变量,但最后唯一有用的是使用-clean参数启动Eclipse。

从Eclipse卸载Maven Integration后错误消失了。

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM