mirror of
https://github.com/sdkman/sdkman-cli.git
synced 2026-01-31 09:43:04 -05:00
Auto detect JAVA_HOME. No longer prereq for installation.
This commit is contained in:
@@ -42,6 +42,34 @@ case "$(uname)" in
|
||||
freebsd=true
|
||||
esac
|
||||
|
||||
# Attempt to set JAVA_HOME if it's not already set.
|
||||
if [ -z "${JAVA_HOME}" ] ; then
|
||||
if ${darwin} ; then
|
||||
[ -z "${JAVA_HOME}" -a -f "/usr/libexec/java_home" ] && export JAVA_HOME=$(/usr/libexec/java_home)
|
||||
[ -z "${JAVA_HOME}" -a -d "/Library/Java/Home" ] && export JAVA_HOME="/Library/Java/Home"
|
||||
[ -z "${JAVA_HOME}" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
|
||||
else
|
||||
javaExecutable="$(which javac)"
|
||||
[ -z "${javaExecutable}" -o "$(expr \"${javaExecutable}\" : '\([^ ]*\)')" = "no" ] && die "GVM: JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME."
|
||||
|
||||
# readlink(1) is not available as standard on Solaris 10.
|
||||
readLink=$(which readlink)
|
||||
[ $(expr "${readLink}" : '\([^ ]*\)') = "no" ] && die "GVM: JAVA_HOME not set and readlink not available, please set JAVA_HOME."
|
||||
javaExecutable="$(readlink -f \"${javaExecutable}\")"
|
||||
javaHome="$(dirname \"${javaExecutable}\")"
|
||||
javaHome=$(expr "${javaHome}" : '\(.*\)/bin')
|
||||
JAVA_HOME="${javaHome}"
|
||||
export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if ${cygwin} ; then
|
||||
[ -n "${JAVACMD}" ] && JAVACMD=$(cygpath --unix "${JAVACMD}")
|
||||
[ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --unix "${JAVA_HOME}")
|
||||
[ -n "${CP}" ] && CP=$(cygpath --path --unix "${CP}")
|
||||
fi
|
||||
|
||||
if [ -z "${GVM_SERVICE}" ]; then
|
||||
export GVM_SERVICE="@GVM_SERVICE@"
|
||||
fi
|
||||
|
||||
@@ -98,40 +98,6 @@ if [ -d "${GVM_DIR}" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Looking for JAVA_HOME..."
|
||||
if [ -z "${JAVA_HOME}" ]; then
|
||||
echo "Not found."
|
||||
echo ""
|
||||
echo "======================================================================================================"
|
||||
echo " Please ensure that you have a Java SDK installed and that JAVA_HOME environment variable is set."
|
||||
echo " accordingly."
|
||||
echo ""
|
||||
echo " Java can be found here:"
|
||||
echo " http://www.oracle.com/technetwork/java/javase/downloads/index.html"
|
||||
echo ""
|
||||
echo " Set JAVA_HOME by editing your ~/.profile file and adding:"
|
||||
echo " export JAVA_HOME=\"/path/to/my/jdk\""
|
||||
echo "======================================================================================================"
|
||||
echo ""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Validating JAVA_HOME..."
|
||||
if [ ! -f "${JAVA_HOME}/bin/java" ]; then
|
||||
echo "Invalid."
|
||||
echo ""
|
||||
echo "======================================================================================================"
|
||||
echo " Please ensure that your JAVA_HOME points to a valid Java SDK."
|
||||
echo " You are currently pointing to:"
|
||||
echo ""
|
||||
echo " ${JAVA_HOME}"
|
||||
echo ""
|
||||
echo " This does not seem to be valid. Please rectify and restart."
|
||||
echo "======================================================================================================"
|
||||
echo ""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Looking for unzip..."
|
||||
if [ -z $(which unzip) ]; then
|
||||
echo "Not found."
|
||||
|
||||
Reference in New Issue
Block a user