68

I want to use the JRE 1.7 that I downloaded from Oracle website.

So I correctly install the .pkg file, and when I try /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version in the terminal I get this :

java version "1.7.0_11" Java(TM) SE Runtime Environment (build 1.7.0_11-b21) Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

But in Eclipse I can't use anything else than JRE 1.6. When I go in Properties > Java Build Path > Add Library > JRE System Library, I can't find the 1.7 (there is only option for it : JavaSE-1.7 (unbound) with this issue :

No JREs in workspace compatible with specified execution environment: JavaSE-1.7

What should I do ? Thanks

Rob
  • 15,732
  • 22
  • 69
  • 107

3 Answers3

99

The download from java.com which installs in /Library/Internet Plug-Ins is only the JRE, for development you probably want to download the JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html and install that instead. This will install the JDK at /Library/Java/JavaVirtualMachines/jdk1.7.0_<something>.jdk/Contents/Home which you can then add to Eclipse via Preferences -> Java -> Installed JREs.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • 2
    Thanks, in Eclipse Kepler Project>Properties>Java Build Path>Add Library>JRE System Library>Installed JREs>Add and worked with e.g.: /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home – Binarian Sep 11 '13 at 05:12
  • 15
    Also! When adding an installed JRE to Eclipse, Eclipse can also "search" for installed JREs. That's how I got Eclipse to connect to my existing installation of 1.7 JDK. – jvriesem Nov 29 '13 at 03:38
  • OH WOW! I spent about 4 hours on this... I installed like 3 different Eclipse's, Java 1.7 and 1.8... all it took was a damn "search" button !! – Someone Somewhere May 25 '14 at 10:38
  • 2
    For some reason, Java 1.6 was installed under /System/Library on my machine, but the Oracle installer put 1.7 under simply /Library. Kind of threw me at first, and the Search... button didn't find the 1.7 install. FYI. – Marvo Sep 02 '14 at 22:29
  • 1
    @Marvo yes, only software from Apple is allowed to install itself under `/System`. Third-party software (which includes Oracle Java) has to go elsewhere. – Ian Roberts Sep 02 '14 at 23:53
  • Actually, the jdk download I just installed appears to have updated the java executable at /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java. It now reports version "1.8.0_25" compared to 1.6 from a few minutes ago. – Matthew Brown Oct 15 '14 at 19:28
  • @MatthewBrown the `java` command in Versions/Current/Commands (and the one in /usr/bin) is a stub that delegates to whichever JDK your `JAVA_HOME` points to, or the most up to date one you have installed if `JAVA_HOME` is not set. The actual 1.8 JDK has installed into /Library/Java – Ian Roberts Oct 15 '14 at 22:04
  • Go to http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and download Java SE Development Kit 8u91 – DeZigny May 27 '16 at 21:26
8

Try editing your eclipse.ini file and add the following at the top

-vm
/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home

Of course the path may be slightly different, looks like I have an older version...

I'm not sure if it will add itself automatically. If not go into

Preferences --> Java --> Installed JREs

Click Add and follow the instructions there to add it

rozner
  • 580
  • 2
  • 5
  • 11
  • Thank you for this. I am really surprised how tough it is to find information on installing and using java. Coming from other open source projects back to using java for now, I am very used to an active, engaged community providing tons of useful information. – Matthew Brown Oct 15 '14 at 19:31
  • It worked with '/Library/java/JavaVirtualMachines/jdk1.8.0_77.jdk/contents/Home/bin' , not this one : '/Library/java/JavaVirtualMachines/jdk1.8.0_77.jdk/contents/Home' – LKM Mar 28 '16 at 12:36
7

You need to tell Eclipse which JDK/JRE's you have installed and where they are located.

This is somewhat burried in the Eclipse preferences: In the Window-Menu select "Preferences". In the Preferences Tree, open the Node "Java" and select "Installed JRE's". Then click on the "Add"-Button in the Panel and select "Standard VM", "Next" and for "JRE Home" click on the "Directory"-Button and select the top level folder of the JDK you want to add.

Its easier than the description may make it look.

Durandal
  • 19,919
  • 4
  • 36
  • 70