OS X Java Versions

OS X uses a weird and wonderful structure for Java components that allows multiple versions of Java to coexist happily on the same system. Depending on what you want to do, choosing between them can create challenges.

Apple references that were useful compiling this article:

Thanks also go to various others who have already plumbed the mysteries of OS X and Java.

OS X Directory Structure

OS X places all kinds of Java components in the directory structure starting at:

/System/Library/Frameworks

The component that’s of particular interest for this discussion is the JavaVM itself. That structure starts at:

/System/Library/Frameworks/JavaVM.framework

Each distinct Java version has a directory in

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

Here’s a sample from my machine

lrwxr-xr-x   1 root  wheel     5B Aug 31 21:35 1.3 -> 1.3.1
drwxr-xr-x   3 root  wheel   102B Jul 20 19:35 1.3.1
lrwxr-xr-x   1 root  wheel     5B Nov 26 03:43 1.5 -> 1.5.0
drwxr-xr-x   8 root  wheel   272B Jan  2  2007 1.5.0
lrwxr-xr-x   1 root  wheel     5B Aug 31 21:35 1.6 -> 1.6.0
drwxr-xr-x   8 root  wheel   272B Oct 18 08:31 1.6.0
drwxr-xr-x   9 root  wheel   306B Oct 18 08:31 A
lrwxr-xr-x   1 root  wheel     1B Aug 31 21:35 Current -> A
lrwxr-xr-x   1 root  wheel     3B Aug 31 21:35 CurrentJDK -> 1.6

There are several interesting points about the subdirectories managed here.

  • The primary release (e.g ’1.5′) is always a link to the corresponding current ‘dot’ or ‘subrelease’ for that version (e.g ’1.5.0′)
  • ‘CurrentJDK’ is linked to whatever is the currently active Java JDK Version
  • ‘Current’ is linked to the currently selected Java SE version

There are several levels of indirection involved. You can stop here if you don’t need a further information or a bad headache. In this excursion, I’ll deal with the 1.6 (Java 6) trajectory.

  • ‘./Current’ is linked to ‘./A’
    • ‘./A’ appears to encompass both Java SE elements and Java JDK elements
    • ‘./A/Commands’ appears to contain JSE binaries
    • ‘./A/Headers’  appears to contain JDK headers
  • ‘./1.6.0′ links to ‘/System/Library/Frameworks/JavaVM.framework/Home’
    • ‘Home’  appears to have JDK binaries fot the specified (default?) version  (debug versions?)

This all serves to set the scene for the most interesting link from the point of view of daily use – ‘/Library/Java/Home’:

/Library/Java/Home -> /System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Home ->
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

This is the directory that Apple recommends using to set the ‘JAVA_HOME’ variable – beloved of the Java world, and required to get almost anything Java-based to work.

export JAVA_HOME=/Library/Java/Home
export PATH=${JAVA_HOME}/bin:${PATH}

Java Versions

Changes that affect everything on the system

If you want to change the Java version for everything on the system, you can do so with the Java Preferences application

/Applications/Utilities/Java Preferences

On the ‘General’ tab, follow the instructions to change the selection.

osx-javapreferences-general

If the version you want doesn’t appear on the list, you need something more radical (To be supplied).

Changes that affect the specific command you’re running

The Apple-sanctioned way to run a specific Java version from the command line is simple.  This deliberately does not involve changing the Java Preferences.

These changes shown below will only apply for the lifetime of the (bash) shell in which they are used. Using the setup illustrated above for my machine:

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
$JAVA_HOME/bin/java

This technique has been tested successfully in two environments:

  • Clean Snow Leopard install – Defaults to Java 1.6 – with manual install of Java 1.5 to run Java 1.5
  • Existing Leopard – default Java 1.5 installation – with manual install of Java 1.6 – to run Java 1.6

Linux NFS Mounts

/usr/sbin/showmount

To see what NFS is explicitly exporting:

/usr/sbin/showmount -e

CIDR address notation

See Classless Inter-Domain Routing

a.b.c.d/n – ‘n’ is the CIDR address mask. It’s the number of leading bits of the IP address that have to be the same.

So a.b.c.d/24 is equivalent to a netmask 255.255.255.000 and so on.

Postgres – Remote access – pg_hba.conf

If you want to enable remote access to a Postgres DB you need two things in pg_hba.conf:

host    all         all         10.1.10.0/24   md5

In the line above

  • A correct netmask or CIDR-format
  • md5 or other security protocol identifier in the ‘method’ column

OS X Snow Leopard Root Password

From Mac OS X Hints – 10.6: Enable root user on Snow Leopard

Here’s how to enable root in Snow Leopard:

  1. Open Directory Utility in its new home, which is /System/Library/CoreServices.
  2. Unlock the application by clicking the padlock icon and entering your Administrator login.
  3. Select Edit » Enable Root User.
  4. Choose Edit » Change Root Password, and choose a password for the root user.

That’s it! Make sure to re-lock the application by clicking the padlock icon.

WordPress Themes