Sunday 24 May 2015

Where is java on Mac Mavericks?

Sometimes you just need to know where java is on the system. I still struggle with this sort of thing on a Mac. So, for my own sanity in future, here is what I found:

Java seems to be put in different places depending on whether you've installed the JRE or the JDK, and also depending on what version you are looking for.

JRE

I recently installed just the JRE for java 1.8.0_40 using the dmg from Oracle. (Ye olde double-click and install method.) This placed java under:

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/

JDK

Find the jdks on the system with:

/usr/libexec/java_home

or

/usr/libexec/java_home -v 1.8

found a directory where my jdks (previously installed) were located. These were under:

/Library/Java/JavaVirtualMachines/

Meanwhile, java 1.6 sdk is sitting under

/System/Library/Java/JavaVirtualMachines/

Setting the default jdk system wide

 (Answer provided by Hughes M. on https://stackoverflow.com/questions/21964709/how-to-set-or-change-the-default-java-jdk-version-on-os-x)
  • leave all JDKs at their default location, under /Library/Java/JavaVirtualMachines. The system will pick the highest version by default.
  • To exclude a JDK from being picked by default, rename its Contents/Info.plist to Info.plist.disabled. That JDK can still be used when $JAVA_HOME points to it, or explicitly referenced in a script or configuration. It will simply be ignored by system's java command.
System launcher will use the JDK with highest version among those that have an Info.plist file.
When working in a shell with alternate JDK, pick your method among existing answers (jenv, or custom aliases/scripts around /usr/libexec/java_home, etc).

 

Setting the default jdk - in a one-off sense

Locate the java versions on the system (see above).

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_121`

 or, if the version is unique, you could use

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

But don't do that second version if you are planning on having later versions installed but not the default.


No comments:

Post a Comment