JAVA_HOME isn’t set by default on OSX. You can resolve this by opening terminal and executing the following:
echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.profile
. ~/.profile
This will cause JAVA_HOME to be set on startup (rather than just the current session), and immediately add it.