简体   繁体   中英

Java for Eclipse compilation JRE issue

I use Mac OS, 10.6 and after recovering my back-up data, Eclipse stopped working. 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. And the Java code still doesn't compile.

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.

Reload Eclipse.

Two possibilities:

1. Update the Installed JRE
(Depending on the issue, one of the following will do)

  • 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

(As you noted)
2. Update the Execution Environment such that it is compatible with the JRE.

Go to Eclipse -> Preferences -> Java -> Installed JREs -> Execution Environment and select a compatible env.

Here is how to fix things up:

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

  2. The jdk is installed into a different location. This will result in IDEs (such as Eclipse) being unable to locate source code and javadocs.

  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; this will no doubt change over time.

  4. Open up eclipse preferences and go to Java --> Installed JREs page

  5. Rather than use the "JVM Contents (MacOS X Default) we will need to use the above JDK location

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

  7. From the Add JRE wizard choose "MacOS X VM" for the JRE Type

  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

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

  10. Finish the wizard and return to the Installed JREs page

  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.

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.

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:

  1. Re-configure the libs.
  2. Update the JRE.
  3. Update the Execution Environment.
  4. 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.

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

I had the same problem on Spring Tool Suite(v 3.7.2) and took the following steps to resolve this :

  1. cd $JAVA_HOME/jre (On a mac)
  2. pwd (This will give the location of JRE directory)
  3. STS > Preferences > Installed JREs > Add the location of the JRE

I had this happen after my system Java updated itself. I restarted Eclipse, it did a build, and the error went away.

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