export PATH="${JAVA_HOME}/bin:${PATH}"
export PATH="${JAVA_HOME}/bin:${PATH}" at the beginning of Connect.sh, or, assuming you use "$JAVA" instead of java all over your scriptassuming you use "$JAVA" instead of java all over your script, remove:
if type -p java >/dev/null; then
JAVA=java
el
or make it the second case, at least:
if [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="$JAVA_HOME/bin/java"
elif type -p java >/dev/null; then
JAVA=java
...
or:
if [ -n "$JAVA_HOME" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA=java
fi
if ! type -p "$JAVA" >/dev/null; then
echo Cannot find java as instructed
exit 1
fi
(Certainly this approach means it should ignore e.g. /usr/bin/java as long as there's a JAVA_HOME env var set, regardless of whether the path in the env var actually exists or so.)