Java for Eclipse 编译 JRE 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15487742/
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
Java for Eclipse compilation JRE issue
提问by cerebrou
I use Mac OS, 10.6 and after recovering my back-up data, Eclipse stopped working. It gives me the following errors:
我使用 Mac OS 10.6,在恢复备份数据后,Eclipse 停止工作。它给了我以下错误:
The container 'JRE System Library [JavaSE-1.6]' references non existing library '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar'
Unbound classpath container: 'JRE System Library [JavaSE-1.7]' in project 'Proba'
I attempted to install again Java Development Kit (Help -> Install new software), and Eclipse actually installed it, but when I go to (Eclipse -> Preferences -> Java -> Installed JREs), I get error "Installed JRE location no longer exists. JRE will be removed. Reason: JRE removed"
, and installed JREs window is indeed empty. And the Java code still doesn't compile.
我尝试再次安装 Java 开发工具包(帮助 -> 安装新软件),而 Eclipse 实际安装了它,但是当我转到(Eclipse -> 首选项 -> Java -> 已安装的 JRE)时,出现错误"Installed JRE location no longer exists. JRE will be removed. Reason: JRE removed"
,并已安装 JRE 窗口确实是空的。Java 代码仍然无法编译。
Solution:Go to: Eclipse -> Preferences -> Java -> Installed JREs -> Execution Environment
and choose the JAVA SE 6 package (possibly JAVA SE 7 could work) and then choose the compatible JREs in the right-hand side.
解决方法:前往:Eclipse -> Preferences -> Java -> Installed JREs -> Execution Environment
选择JAVA SE 6包(可能JAVA SE 7也可以),然后在右侧选择兼容的JRE。
Reload Eclipse.
重新加载 Eclipse。
回答by cmd
Two possibilities:
两种可能:
1. Update the Installed JRE
(Depending on the issue, one of the following will do)
1. 更新已安装的 JRE
(根据问题,执行以下操作之一)
Remove and Recreate the
Installed JREs
instance for the failing JVM.Eclipse -> Preferences -> Java -> Installed JRE
Install a new version of Java. (You can get it here), then Create a new instance using Eclipse's 'Installed JREs'. Set it as the default.
Eclipse -> Preferences -> Java -> Installed JRE
Installed JREs
为失败的 JVM删除并重新创建实例。Eclipse -> Preferences -> Java -> Installed JRE
安装新版本的 Java。(您可以在此处获取),然后使用 Eclipse 的“已安装的 JRE”创建一个新实例。将其设置为默认值。
Eclipse -> Preferences -> Java -> Installed JRE
(As you noted)
2. Update the Execution Environment
such that it is compatible with the JRE.
(正如您所指出的)
2. 更新Execution Environment
它以使其与 JRE 兼容。
Go to Eclipse -> Preferences -> Java -> Installed JREs -> Execution Environment
and select a compatible env.
转到Eclipse -> Preferences -> Java -> Installed JREs -> Execution Environment
并选择一个兼容的环境。
回答by user3296594
Here is how to fix things up:
以下是解决问题的方法:
Some versions in Mac like Lion does not come with a JDK; you can go and download one directly from http://connect.apple.com. Yes you need to sign up and login with your apple id. The download column is over on the right; and you should be able to find your way.
The jdk is installed into a different location. This will result in IDEs (such as Eclipse) being unable to locate source code and javadocs.
At the time of writing the JDK ended up here: /Library/Java/JavaVirtualMachines/1.6.0_31-b04-415.jdk/Contents/Home Please go ahead and have a look to confirm where your JDK ended up; this will no doubt change over time.
Open up eclipse preferences and go to Java --> Installed JREs page
Rather than use the "JVM Contents (MacOS X Default) we will need to use the above JDK location
At the time of writing the Search button was not aware of the new JDK location; we we will need to click on the Add button and hunt it down ourselves.
From the Add JRE wizard choose "MacOS X VM" for the JRE Type
For the JRE Definition Page we need to fill in the following: JRE Home:/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home
The other fields will now auto fill, with the default JRE name being "Home". You can quickly correct this to something more meaningful: JRE name:System JDK
Finish the wizard and return to the Installed JREs page
Choose "System JDK" from the list You can now developer normally with javadocs correctly shown for for the base classes like java.lang.String, source code correctly shown when debugging.
Mac 中的某些版本(如 Lion)没有 JDK;你可以直接从http://connect.apple.com下载一个。是的,您需要注册并使用您的 Apple ID 登录。下载栏在右边结束;你应该能够找到自己的路。
jdk 安装到不同的位置。这将导致 IDE(例如 Eclipse)无法定位源代码和 javadoc。
在撰写本文时,JDK 位于:/Library/Java/JavaVirtualMachines/1.6.0_31-b04-415.jdk/Contents/Home 请继续查看以确认您的 JDK 在哪里;这无疑会随着时间的推移而改变。
打开 eclipse 首选项并转到 Java --> Installed JREs 页面
我们需要使用上面的 JDK 位置,而不是使用“JVM 内容(MacOS X 默认)”
在撰写本文时,搜索按钮不知道新的 JDK 位置;我们需要单击“添加”按钮并自己搜索它。
从添加 JRE 向导中,为 JRE 类型选择“MacOS X VM”
对于 JRE 定义页面,我们需要填写以下内容: JRE Home:/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home
其他字段现在将自动填充,默认 JRE 名称为“Home”。您可以快速将其更正为更有意义的内容:JRE name:System JDK
完成向导并返回到已安装的 JRE 页面
从列表中选择“System JDK”您现在可以正常开发人员,正确显示java.lang.String等基类的javadoc,调试时正确显示源代码。
回答by Diferdin
The error above is simply saying that the Eclipse variable your JREs/JDKs have moved and the relevant variables defined within Eclipse point to locations that no longer exist now.
上面的错误只是说明您的 JRE/JDK 已经移动了 Eclipse 变量,并且在 Eclipse 中定义的相关变量指向现在不再存在的位置。
All you have to do is to point those variables to the new location, and the methods suggested above are good to go.
您所要做的就是将这些变量指向新位置,并且上面建议的方法很好。
回答by D3X
4 Possible Alternatives:
4 种可能的选择:
- Re-configure the libs.
- Update the JRE.
- Update the Execution Environment.
- Check for MAC Updates. //Some versions of Mac does not have support for JDK by default. But you can re-configure this to solve your issue by using JDK rather than Mac Default variables.
- 重新配置库。
- 更新 JRE。
- 更新执行环境。
- 检查 MAC 更新。//某些版本的Mac默认不支持JDK。但是您可以重新配置它以通过使用 JDK 而不是 Mac 默认变量来解决您的问题。
One more thing which you can try is, to restore the Eclipse to Default state, i.e., re-install the version of Eclipse which you are using.(By the way, this worked for me, when I had a similar issue).
您可以尝试的另一件事是将 Eclipse 恢复到默认状态,即重新安装您正在使用的 Eclipse 版本。(顺便说一句,这对我有用,当我遇到类似问题时)。
回答by Rajat Bhatnagar
I had the same problem on Spring Tool Suite(v 3.7.2) and took the following steps to resolve this :
我在 Spring Tool Suite(v 3.7.2) 上遇到了同样的问题,并采取了以下步骤来解决这个问题:
- cd $JAVA_HOME/jre (On a mac)
- pwd (This will give the location of JRE directory)
- STS > Preferences > Installed JREs > Add the location of the JRE
- cd $JAVA_HOME/jre(在 Mac 上)
- pwd(这将给出 JRE 目录的位置)
- STS > 首选项 > 已安装的 JRE > 添加 JRE 的位置
回答by Noumenon
I had this happen after my system Java updated itself. I restarted Eclipse, it did a build, and the error went away.
我的系统 Java 自我更新后发生了这种情况。我重新启动了 Eclipse,它进行了构建,错误消失了。