KNOX-3024 - Fixed Java finding issues (#891)

diff --git a/gateway-release-common/home/bin/knox-functions.sh b/gateway-release-common/home/bin/knox-functions.sh
index 1a5dc5c..726ff85 100644
--- a/gateway-release-common/home/bin/knox-functions.sh
+++ b/gateway-release-common/home/bin/knox-functions.sh
@@ -50,6 +50,17 @@
 ##### common functions #####
 ############################
 
+function setVerbose() {
+  export VERBOSE=false
+  for arg in "$@"; do
+    # Check if the argument contains the search string
+    if [[ $arg == *"--verbose"* ]]; then
+      export VERBOSE=true
+      break
+    fi
+  done
+}
+
 JAVA_VERSION_PATTERNS=( "1.6.0_31/bin/java$" "1.6.0_.*/bin/java$" "1.6.0.*/bin/java$" "1.6\..*/bin/java$" "/bin/java$" )
 
 function findJava() {
@@ -72,7 +83,7 @@
 
   # Try to find java on PATH.
   if [ "$JAVA" == "" ]; then
-    JAVA=$(command -v java 2>/dev/null)
+    JAVA=$(which java 2>/dev/null)
     if [ ! -x "$JAVA" ]; then
       JAVA=""
     fi
@@ -82,9 +93,8 @@
   if [ "$JAVA" == "" ]; then
     for pattern in "${JAVA_VERSION_PATTERNS[@]}"; do
       # shellcheck disable=SC2207
-      JAVAS=( $(find /usr -executable -name java -print 2> /dev/null | grep "$pattern" | head -n 1 ) )
+      JAVA=$(find /usr -executable -name java -print 2> /dev/null | grep "$pattern" | head -n 1 )
       if [ -x "$JAVA" ]; then
-        JAVA=${JAVAS[1]}
         break
       else
         JAVA=""
@@ -98,6 +108,8 @@
 
   if [[ -z $JAVA ]]; then
     echo "Warning: JAVA is not set and could not be found." 1>&2
+  elif [[ "$VERBOSE" = "true" ]]; then
+    echo "Found Java at $JAVA"
   fi
 }
 
diff --git a/gateway-release/home/bin/gateway.sh b/gateway-release/home/bin/gateway.sh
index ba0ec17..18b2287 100755
--- a/gateway-release/home/bin/gateway.sh
+++ b/gateway-release/home/bin/gateway.sh
@@ -26,9 +26,11 @@
 # Start/stop script location
 APP_BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
+# shellcheck disable=SC1091
 # Setup the common environment
 . "$APP_BIN_DIR"/knox-env.sh
 
+# shellcheck disable=SC1091
 # Source common functions
 . "$APP_BIN_DIR"/knox-functions.sh
 
@@ -103,6 +105,7 @@
 }
 
 function main {
+   setVerbose "$@"
    checkJava
 
    case "$1" in
diff --git a/gateway-release/home/bin/knoxcli.sh b/gateway-release/home/bin/knoxcli.sh
index 08573c4..3477e70 100755
--- a/gateway-release/home/bin/knoxcli.sh
+++ b/gateway-release/home/bin/knoxcli.sh
@@ -26,9 +26,11 @@
 # The app's jar name
 APP_JAR="$APP_BIN_DIR/knoxcli.jar"
 
+# shellcheck disable=SC1091
 # Setup the common environment
 . "$APP_BIN_DIR"/knox-env.sh
 
+# shellcheck disable=SC1091
 # Source common functions
 . "$APP_BIN_DIR"/knox-functions.sh
 
@@ -72,6 +74,7 @@
 }
 
 function main {
+   setVerbose "$@"
    checkJava
    buildAppJavaOpts
    $JAVA "${APP_JAVA_OPTS[@]}" -jar "$APP_JAR" "$@" || exit 1
diff --git a/gateway-release/home/bin/ldap.sh b/gateway-release/home/bin/ldap.sh
index 763af6f..2d16786 100755
--- a/gateway-release/home/bin/ldap.sh
+++ b/gateway-release/home/bin/ldap.sh
@@ -29,9 +29,11 @@
 # The app's JAR name
 export APP_JAR="$APP_BIN_DIR/ldap.jar"
 
+# shellcheck disable=SC1091
 # Setup the common environment
 . "$APP_BIN_DIR"/knox-env.sh
 
+# shellcheck disable=SC1091
 # Source common functions
 . "${APP_BIN_DIR}"/knox-functions.sh
 
@@ -65,6 +67,7 @@
 export APP_RUNNING_IN_FOREGROUND=${KNOX_LDAP_RUNNING_IN_FOREGROUND:-$DEFAULT_APP_RUNNING_IN_FOREGROUND}
 
 function main {
+   setVerbose "$@"
    checkJava
 
    case "$1" in