Java 未绑定的类路径变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29560600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unbound classpath variable
提问by DasBooten
When rebuilding my project with Maven I sometimes get hundreds of
使用 Maven 重建我的项目时,我有时会得到数百个
'unbound classpath variable M2_REPO/etc/..'
'未绑定的类路径变量 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.
当实际通过文件系统时,它详细说明不存在的 jars 实际上存在。Eclipse 只是出于某种原因没有看到它们。我的 m2_repo 在我的首选项->java->classpathvariables 部分中被正确引用,我的环境变量也被正确设置。
Any ideas for me folks?
伙计们对我有什么想法吗?
采纳答案by Jordi Castilla
If you already did several times STEP 1, go to STEP 2
STEP 1
Try deleting and redefining env vars:
如果您已经多次执行STEP 1,请转到STEP 2
STEP 1
尝试删除并重新定义 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.
- 打开 Eclipse Preferences [Window - Preferences]
- 转到 [Java - 构建路径 - 类路径变量]
- 单击新建并将其名称设置为 M2_REPO
- 单击文件夹并选择您的 Maven 存储库文件夹。例如,我的存储库文件夹是
C:/Users/user/.m2/repository
- 重建项目。
Beside from inside of Eclipse, you can also add the M2_REPO variablefrom command line using this Maven command:
除了在 Eclipse 内部,您还可以使用以下 Maven 命令从命令行添加M2_REPO 变量:
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
STEP 2
If your build path is correctly defined, check Maven settings.xml:
STEP 2
如果您的构建路径定义正确,请检查 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).
如果没有,请将其设置在那里并在 settings.xml 内的设置标记中更改 localRepository 路径。通常您会在用户文件夹下的 .m2 文件夹中找到 settings.xml(例如 C:\Documents and Settings\userName.m2)。
回答by Sudhir Srinivasan
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.
我不止一次见过这个问题,我不使用 maven 插件,所以我没有 windows -> Preferences->Maven。要解决此问题 'unbound classpath variable M2_REPO/etc/..
,尽管您有 M2_REPO 变量设置问题 -> 将 M2_REPO 变量重命名为其他名称(例如 M2_REPO2),然后将其改正为 M2_REPO,此问题就会消失。
回答by Zolbayar
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:
好吧,我尝试了@Jordi 的回答中的步骤。但那些没有任何区别。我在 eclipse 中尝试了一些仪式性的东西,例如:
- closing the project and opening it
- restarting the IDE
- cleaning and rebuilding etc...
- 关闭项目并打开它
- 重新启动IDE
- 清洁和重建等...
with no success.
没有成功。
Then strange thing happened when I changed the Java complience level to 1.8and revert it back to 1.6. It worked! All unbound classpath variable errors are gone now.
然后当我将 Java 合规级别更改为1.8并将其恢复为1.6时,发生了奇怪的事情。有效!所有未绑定的类路径变量错误现在都消失了。
回答by Neill
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.
Mars.2 对我来说有这个问题。尝试了所有这些建议,然后删除 ~/.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. 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.
通过查看 Maven - 用户设置到达那里,但没有 settings.xml,但有一个 .metadata 文件夹,如果您深入查看,有一个 jdt 文件,其中包含 eclipse .m2 存储库位置。觉得效果不好,就删了。重启eclipse并配置好M2_REPO后,~/.m2/repository/.metadata文件夹还是被删除了。必须与工作区中的其他内容发生冲突。不知道它最初是如何到达那里的。
回答by Akash
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 ORright-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
祝你好运
回答by tok
I tried setting the M2_REPO variable several times, but finally the only thing helped was starting Eclipse with -cleanparameter.
我多次尝试设置 M2_REPO 变量,但最后唯一有帮助的是使用-clean参数启动 Eclipse 。
回答by Zhen
Error was gone after uninstall of the Maven Integration from Eclipse.
从 Eclipse 卸载 Maven 集成后错误消失了。
回答by Jerfi.K
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...
希望对你有帮助...
回答by ptanov
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
(NOTeclipse:add-maven-repo
as sugested in the first answer)
行家命令是:
mvn -Declipse.workspace="path-to-eclipse-workspace" eclipse:configure-workspace
(NOTeclipse:add-maven-repo
在第一个答案为sugested)