-3

I recently started using MacOS and I think that my IDE is not finding the proper JDK path. Here's what I've done.

Initially when I got my Mac I installed the JDK from Apple's website (I thought it would just work if I got that version). It seemed like it worked until I tried importing a project into Eclipse and it said JDK 7 was requires (the version from Apple is only version 6).

I then downloaded JDK 8 from Oracle and installed. I know that after this step I having to do this. However I am not sure where this new install is located (for whatever reason, when this program installs it doesn't show any sort of directory so I have no idea where it went).

Searching "jdk" for the install directory I have found:

  • It's not in applications (which makes sense, but that's where everything else goes that I have installed).

  • I tried searching Macintosh HD and I don't see anything (I feel like something went wrong here because why wouldn't this work?). Is Macintosh HD the closest-to-root directory on MacOS?

Thomas Schmidt
  • 1,248
  • 2
  • 12
  • 37
OKGimmeMoney
  • 575
  • 2
  • 7
  • 19
  • I searched the site before I posted my question and looked at the suggested posts before I posted my question. The answer that's a "duplicate" doesn't work for me. – OKGimmeMoney Apr 24 '15 at 20:02
  • For any mods looking at this I'd like to point out that this question is marked as a duplicate however the solution that was posted here isn't in the duplicate post and this is the solution that worked for me. This is an official request to fix this problem (no I don't know how to fix it, but marking it as a duplicate isn't helpful to those who need this solution). – OKGimmeMoney Apr 24 '15 at 21:09

2 Answers2

3

To find the current home of the JDK on MacOS, type this in Terminal:

/usr/libexec/java_home

On my machine, this yields:

/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home

but note that your version is probably different, so run the command, don't copy-paste the result.

To find all existing JDKs, including previous versions:

/usr/libexec/java_home -V

On my machine this yields:

    1.8.0_40, x86_64:   "Java SE 8"     /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
    1.7.0_71, x86_64:   "Java SE 7"     /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
    1.7.0_67, x86_64:   "Java SE 7"     /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home

Now, make sure your Eclipse sees at least one of these. Open its preferences:

Eclipse Preferences - Installed JREs

If your JRE does not appear there, add it. If it does, go to your project's build path and make sure it appears there as well. In Project→Properties, you are supposed to see:

enter image description here

RealSkeptic
  • 33,993
  • 7
  • 53
  • 79
  • Just before you posted this I tried the command 'which java' and it gave me a directory that way. But it still doesn't seem to work. Can you confirm whether this is a valid way to reliably find the correct JDK directory? – OKGimmeMoney Apr 24 '15 at 19:20
  • 1
    @OKGimmeMoney that only gives you the path to the `java` command, not the `java home`, which is what IDEs usually need. The `java` command is a symbolic link. If you want to use a different version (for testing purpuses etc.) you'll need to access the one in the actual Java home, or change the current java home, so knowing the java home is important. – RealSkeptic Apr 24 '15 at 19:22
  • OK, I see /usr/libexec/java_home exists but what do I do so that Eclipse can recognize it? I'm getting this error when I create a new project (as well as in existing projects): The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files – OKGimmeMoney Apr 24 '15 at 19:34
  • 1
    OK, I have expanded my answer. – RealSkeptic Apr 24 '15 at 20:06
0

The current update 45 of the Java 8 JDK installs in to

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
greg-449
  • 109,219
  • 232
  • 102
  • 145