简体   繁体   English

未绑定的classpath变量

[英]Unbound classpath variable

When rebuilding my project with Maven I sometimes get hundreds of 当用Maven重建我的项目时,我有时会得到数百个

'unbound classpath variable M2_REPO/etc/..' '未绑定的classpath变量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. Eclipse出于某种原因没有看到它们。 My m2_repo is correctly referenced in my preferences->java->classpathvariables section and my environmental variables are likewise properly set. 在我的preferences-> java-> classpathvariables部分中正确引用了我的m2_repo,同样也正确设置了我的环境变量。

Any ideas for me folks? 对我来说有什么想法吗?

If you already did several times STEP 1 , go to STEP 2 如果您已经多次执行STEP 1 ,请转到步骤2

STEP 1 步骤1
Try deleting and redefining env vars: 尝试删除并重新定义env vars:

  • Open the Eclipse Preferences [Window - Preferences] 打开Eclipse首选项[窗口 - 首选项]
  • Go to [Java - Build Path - Classpath Variables] 转到[Java - 构建路径 - 类路径变量]
  • Click New and set its name as M2_REPO 单击“新建”并将其名称设置为M2_REPO
  • Click Folder and select your Maven repository folder. 单击“文件夹”并选择Maven存储库文件夹。 For example, my repository folder is C:/Users/user/.m2/repository 例如,我的存储库文件夹是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: 除了Eclipse内部, 您还可以使用此Maven命令从命令行添加M2_REPO变量

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


STEP 2 第2步
If your build path is correctly defined, check Maven settings.xml: 如果正确定义了构建路径,请检查Maven settings.xml:

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

If not, set it there and change localRepository path in settings tag inside settings.xml. 如果没有,请将其设置在那里并更改settings.xml中settings标签中的localRepository路径。 Normally you will find settings.xml in .m2 folder under the user folder (for eg. C:\\Documents and Settings\\userName.m2). 通常,您会在用户文件夹下的.m2文件夹中找到settings.xml(例如,C:\\ Documents and Settings \\ userName.m2)。

Well, I tried the steps in @Jordi's answer. 好吧,我尝试了@Jordi的答案中的步骤。 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 重新启动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 . 然后,当我将Java complience级别更改为1.8并将其恢复为1.6时,发生了奇怪的事情。 It worked! 有效! All unbound classpath variable errors are gone now. 所有未绑定的类路径变量错误现在都消失了。

Update Project worked for me : Update Project为我工作:

Step 1 : Select Project Folder 第1步:选择项目文件夹

Select the project folder that is giving the error. 选择提供错误的项目文件夹。

Step 2 : Update Maven Project 第2步:更新Maven项目

Alt + F5 shortcut OR right-click >> Maven >> Update Project . Alt + F5快捷方式 right-click >> Maven >> Update Project

Step 3 : Finalize 第3步:完成

Click OK and let it update . Click OK并让其更新

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. 我不止一次见过这个问题而且我没有使用maven插件所以我没有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. 要解决此'unbound classpath variable M2_REPO/etc/.. ”,尽管您有M2_REPO变量设置问题 - >将M2_REPO变量重命名为其他内容(例如M2_REPO2),然后将其更正回M2_REPO,此问题就会消失。

Mars.2 was having this problem for me. Mars.2对我有这个问题。 Tried all these suggestions, then deleted the ~/.m2/repository/.metadata folder, restarted eclipse, and M2_REPO was there. 尝试了所有这些建议,然后删除了〜/ .m2 / repository / .metadata文件夹,重新启动了eclipse,并且M2_REPO就在那里。

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. 通过查看Maven - 用户设置到达那里,但是没有settings.xml,但是有一个.metadata文件夹,如果你向下钻取一个带有eclipse .m2存储库位置的jdt文件。 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. 重新启动eclipse并配置M2_REPO后,仍然会删除〜/ .m2 / repository / .metadata文件夹。 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....) 你会看到你在问题中看到的所有罐子(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 注意:在此之前我也做了mvn clean install,更新项目时没有帮助我试过这个

Hope helps for you... 希望对你有帮助......

M2_REPO should point to ~/.m2/repository (in Eclpise Windows > Preferences > Java > Build Path > Classpath Variables > New... ) M2_REPO应指向~/.m2/repository (在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) maven命令是: mvn -Declipse.workspace="path-to-eclipse-workspace" eclipse:configure-workspace不是 eclipse:add-maven-repo在第一个答案中消化了)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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