Skip to content

Instantly share code, notes, and snippets.

@loplex
Last active May 16, 2022 15:09
Show Gist options
  • Save loplex/daadc2a021541097f20af7e3d123a46f to your computer and use it in GitHub Desktop.
Save loplex/daadc2a021541097f20af7e3d123a46f to your computer and use it in GitHub Desktop.
# add to your ~/.bashrc either direct content of this file or the following line:
# . /path/to/this/file.sh
jhome() {
java_home="$(/usr/libexec/java_home -f -v "$@")"
local err_handler='{ printf "%s\n" "ERROR!!!"; ls -ld "${java_home}"{,/bin,/bin/java}; /usr/libexec/java_home -V; return 1; }'
{ [ -n "${java_home}" ] && [ -d "${java_home}" ] && [ -d "${java_home}/bin" ] && [ -f "${java_home}/bin/java" ] && [ -x "${java_home}/bin/java" ]; } || eval "${err_handler}"
export JAVA_HOME="${java_home}"
export PATH="${JAVA_HOME}/bin:${PATH}"
echo "JAVA_HOME: ${JAVA_HOME}"
echo '`java -version`:'; java -version || eval "${err_handler}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment