Why doesn't /usr/libexec/java_home recognize JDK 1.8?

I am trying to install a JDK 8 on OS X Mountain Lion (to experiment with the new lambda features).

Starting point

A machine recently updated from OS X 10.6 to 10.8, with

$ sw_vers
  ProductName:    Mac OS X
  ProductVersion: 10.8.2
  BuildVersion:   12C60

$ ls -l /Library/Java/JavaVirtualMachines/
  Home@ -> jdk1.7.0_09.jdk/Contents/Home/
  jdk1.7.0_09.jdk/

$ ls -l /System/Library/Java/JavaVirtualMachines/
  1.6.0.jdk/

and this folder from the OS X 10.6 era:

/System/Library/Frameworks/JavaVM.framework/Versions/

In ~/.bashrc I've set

export JAVA_HOME=/Library/Java/JavaVirtualMachines/Home

So I have

$ java -version
  java version "1.7.0_09"
  Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
  Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

$ /usr/libexec/java_home
  /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home

How I installed JDK 8

  1. Downloaded the .tar.gz file from http://jdk8.java.net/lambda/ and unpacked it into

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

    (I created the folders jdk1.8.0.jdk/Contents/Home manually)

  2. Changed the symlink /Library/Java/JavaVirtualMachines/Home to point to jdk1.8

Now I have

$ java -version
  openjdk version "1.8.0-ea"
  OpenJDK Runtime Environment (build 1.8.0-ea-lambda-nightly-h2135-20121203-b67-b00)
  OpenJDK 64-Bit Server VM (build 25.0-b05, mixed mode)

$ echo $JAVA_HOME
  /Library/Java/JavaVirtualMachines/Home

$ ls /Library/Java/JavaVirtualMachines
  Home@ -> jdk1.8.0.jdk/Contents/Home/
  ...

But the java_home utility doesn't seem to care:

$ /usr/libexec/java_home 
  /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home

It doesn't even know that there is a JDK 8 available:

$ /usr/libexec/java_home -v 1.8*
  Unable to find any JVMs matching version "1.8*".

Question

I'd like the /usr/libexec/java_home utility to find my installed JDKs, so I can use something like this:

alias setjdk17='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7*)'
alias setjdk18='export JAVA_HOME=$(/usr/libexec/java_home -v 1.8*)'

and get rid of the Home symlink. Does anyone know

  • how I can properly install JDK 8?
  • how I can make /usr/libexec/java_home recognize it?

Solution 1:

You need to also copy the Contents/MacOS directory and Info.plist from the 1.7 SDK and adapt them (by changing the version strings in it).

Then you can:

$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
$ java -version
openjdk version "1.8.0-ea"
$ /usr/libexec/java_home -v 1.8*
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home

Note that this is a hack and I didn't try anything else than start java... I was just building on your tip of creating the package.