简体   繁体   English

Java for Eclipse编译JRE问题

[英]Java for Eclipse compilation JRE issue

I use Mac OS, 10.6 and after recovering my back-up data, Eclipse stopped working. 我使用Mac OS,10.6并在恢复备份数据后,Eclipse停止工作。 It gives me the following errors: 它给了我以下错误:

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. 我尝试再次安装Java Development Kit(帮助 - >安装新软件),Eclipse实际安装了它,但是当我去(Eclipse - > Preferences - > Java - > Installed JREs)时,我收到错误"Installed JRE location no longer exists. JRE will be removed. Reason: JRE removed" ,并且已安装的JRE窗口确实为空。 And the Java code still doesn't compile. 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。

Two possibilities: 两种可能性:

1. Update the Installed JRE 1.更新已安装的JRE
(Depending on the issue, one of the following will do) (根据问题,以下之一会做)

  • Remove and Recreate the Installed JREs instance for the failing JVM. 为失败的JVM删除并重新创建已Installed JREs实例。

    Eclipse -> Preferences -> Java -> Installed JRE

  • Install a new version of Java. 安装新版本的Java。 (You can get it here ), then Create a new instance using Eclipse's 'Installed JREs'. (你可以在这里得到它),然后使用Eclipse的'Installed JREs'创建一个新实例。 Set it as the default. 将其设置为默认值。

    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并选择兼容的env。

Here is how to fix things up: 以下是解决问题的方法:

  1. Some versions in Mac like Lion does not come with a JDK; 像Lion这样的Mac中的某些版本没有JDK; you can go and download one directly from http://connect.apple.com . 你可以直接从http://connect.apple.com下载一个。 Yes you need to sign up and login with your apple id. 是的,您需要注册并使用您的苹果ID登录。 The download column is over on the right; 下载列在右侧; and you should be able to find your way. 你应该能够找到自己的方式。

  2. The jdk is installed into a different location. jdk安装在不同的位置。 This will result in IDEs (such as Eclipse) being unable to locate source code and javadocs. 这将导致IDE(例如Eclipse)无法找到源代码和javadoc。

  3. 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; 在撰写本文时,JDK最终在此处:/ Library / Java / JavaVirtualMachines / 1.6.0_31-b04-415.jdk / Constates / Home请继续查看JDK的最终位置; this will no doubt change over time. 这无疑会随着时间而改变。

  4. Open up eclipse preferences and go to Java --> Installed JREs page 打开eclipse首选项并转到Java - > Installed JREs页面

  5. Rather than use the "JVM Contents (MacOS X Default) we will need to use the above JDK location 而不是使用“JVM内容(MacOS X默认)”,我们将需要使用上面的JDK位置

  6. At the time of writing the Search button was not aware of the new JDK location; 在撰写本文时,“搜索”按钮不知道新的JDK位置; we we will need to click on the Add button and hunt it down ourselves. 我们需要点击“添加”按钮并自行搜索。

  7. From the Add JRE wizard choose "MacOS X VM" for the JRE Type 从Add JRE向导中,为JRE Type选择“MacOS X VM”

  8. 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 对于JRE定义页面,我们需要填写以下内容:JRE主页:/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home

  9. The other fields will now auto fill, with the default JRE name being "Home". 其他字段现在将自动填充,默认JRE名称为“Home”。 You can quickly correct this to something more meaningful: JRE name:System JDK 您可以快速将其更正为更有意义的内容:JRE名称:System JDK

  10. Finish the wizard and return to the Installed JREs page 完成向导并返回“已安装的JRE”页面

  11. 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. 从列表中选择“System JDK”您现在可以正常开发javadocs,正确显示基类,如java.lang.String,调试时正确显示的源代码。

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. 您所要做的就是将这些变量指向新位置,并且上面建议的方法很好。

4 Possible Alternatives: 4种可能的替代方案:

  1. Re-configure the libs. 重新配置库。
  2. Update the JRE. 更新JRE。
  3. Update the Execution Environment. 更新执行环境。
  4. Check for MAC Updates. 检查MAC更新。 //Some versions of Mac does not have support for JDK by default. //默认情况下,某些版本的Mac不支持JDK。 But you can re-configure this to solve your issue by using JDK rather than Mac Default variables. 但您可以通过使用JDK而不是Mac Default变量重新配置它来解决您的问题。

One more thing which you can try is, to restore the Eclipse to Default state, ie, 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版本。(顺便说一下,当我遇到类似的问题时,这对我有用)。

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)上遇到了同样的问题,并采取了以下步骤来解决这个问题:

  1. cd $JAVA_HOME/jre (On a mac) cd $ JAVA_HOME / jre(在Mac上)
  2. pwd (This will give the location of JRE directory) pwd(这将给出JRE目录的位置)
  3. STS > Preferences > Installed JREs > Add the location of the JRE STS>首选项>已安装的JRE>添加JRE的位置

I had this happen after my system Java updated itself. 我的系统Java更新后发生了这种情况。 I restarted Eclipse, it did a build, and the error went away. 我重新启动了Eclipse,它进行了构建,错误消失了。

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

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