My work Mac was upgraded by the company's 'managed software updates' (sigh) that switched it to Java 8. This wreaked havoc with subsequent releases of deployed applications for the clients that are still running Java 7.
I use the shell (via 'ant') to deploy the applications and found this way to set the compiler back to Java 7.
Set JAVA_HOME in ~/.profile to: export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
This worked for me, but is it the correct way?