Setting JAVA_HOME for JDK6 on Linux and OSX

Here is a useful little code snippet I use as part of BigSQL.

if [ "x$JAVA_HOME" == "x" ]; then
  macosx_j6="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
  ubuntu_j6="/usr/lib/jvm/java-6-openjdk-amd64"
  redhat_j6="/usr/lib/jvm/java-1.6.0-openjdk.x86_64"
  if [ -d "$macosx_j6" ]; then
    export JAVA_HOME="$macosx_j6"
  elif [ -d "$ubuntu_j6" ]; then
    export JAVA_HOME="$ubuntu_j6"
  elif [ -d "$redhat_j6" ]; then
    export JAVA_HOME="$redhat_j6"
  else
    echo "WARNING: Cannot figure out JAVA_HOME."
    exit 3
  fi
fi

Bash Script for setting JAVA_HOME

Bash Script for setting JAVA_HOME on Linux & OSX

jvmVer=`java -version 2>&1 | grep "java version" | awk '{print $3}' | tr -d \"`
rc=$?
if [ ! "$rc" == "0" ]; then
  echo " "
  echo "ERROR: JDK does not appear to be installed."
  exit 3
fi

if [ "x$JAVA_HOME" == "x" ]; then
  osName=`uname`
  if [ "$osName" == "Darwin" ]; then
    JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
  else
    JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64
  fi
fi