Last active
May 16, 2022 15:09
-
-
Save loplex/daadc2a021541097f20af7e3d123a46f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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