More intelligent setting of JAVA_HOME