-
Notifications
You must be signed in to change notification settings - Fork 35
/
use-j17.sh
38 lines (31 loc) · 1.18 KB
/
use-j17.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
JAVA_HOME_FOLDER=$(ls -lah /usr/lib/jvm | grep "java-17-openjdk-.*\.x86_64" | awk '{print $NF}' | head -1)
JAVA_VERSION="17"
function msg_and_exit() {
echo "ERROR: ${1}"
exit 1
}
echo "Switching to java ${JAVA_VERSION}:"
JAVA_HOME="/usr/lib/jvm/${JAVA_HOME_FOLDER}"
alternatives --set java ${JAVA_HOME}/bin/java || \
msg_and_exit "Cannot configure java ${JAVA_VERSION} as the alternative to use for java."
java -version 2>&1 | grep -q "\s\+${JAVA_VERSION}" || msg_and_exit "Java version is not ${JAVA_VERSION}."
if [ -x ${JAVA_HOME}/bin/javac ]; then
alternatives --set javac ${JAVA_HOME}/bin/javac || \
msg_and_exit "Cannot configure javac ${JAVA_VERSION} as the alternative to use for javac."
javac -version 2>&1 | grep -q "\s\+${JAVA_VERSION}" || msg_and_exit "Javac version is not ${JAVA_VERSION}."
else
echo "WARNING: Not found binary for javac in path ${JAVA_HOME}/bin/javac "
fi
java -version 2>&1
if which 'javac'; then
javac -version 2>&1
else
echo "WARNING: Binary javac is not available."
fi
if [ -d ${JAVA_HOME}/bin/ ]; then
export JAVA_HOME
else
msg_and_exit "Cannot configure JAVA_HOME environment variable to ${JAVA_HOME}"
fi
echo "JAVA_HOME: $JAVA_HOME"