aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitris Kavvathas <dimitris.kavvathas@sonarsource.com>2022-08-10 12:29:37 +0200
committersonartech <sonartech@sonarsource.com>2022-08-10 20:03:08 +0000
commitdf33da63fdc8a5e46183600f85801a120c2c9dca (patch)
tree9ca04e04105107251a4b03d3cc0017d0bdb7abe5
parent5a0bc2b8089eff9fd713550a41c3a6c56ff49399 (diff)
downloadsonarqube-df33da63fdc8a5e46183600f85801a120c2c9dca.tar.gz
sonarqube-df33da63fdc8a5e46183600f85801a120c2c9dca.zip
SONAR-17136 Add SONAR_JAVA_PATH env variable support for user-defined Java executable
-rw-r--r--server/sonar-docs/src/pages/setup/install-server.md4
-rwxr-xr-xsonar-application/src/main/assembly/bin/linux-x86-64/sonar.sh20
2 files changed, 20 insertions, 4 deletions
diff --git a/server/sonar-docs/src/pages/setup/install-server.md b/server/sonar-docs/src/pages/setup/install-server.md
index dc655a26fb8..7906e686a38 100644
--- a/server/sonar-docs/src/pages/setup/install-server.md
+++ b/server/sonar-docs/src/pages/setup/install-server.md
@@ -164,12 +164,12 @@ It is possible to overwrite the default Java executable by setting the environme
#### Linux / MacOS
```
-SONAR_JAVA_PATH="path/to/java_home/bin/java"
+export SONAR_JAVA_PATH="path/to/java_home/bin/java"
```
#### Windows
```
-SONAR_JAVA_PATH="C:\Program Files\java_home\bin\java.exe"
+setx SONAR_JAVA_PATH "C:\Program Files\java_home\bin\java.exe"
```
### Advanced Installation Features
diff --git a/sonar-application/src/main/assembly/bin/linux-x86-64/sonar.sh b/sonar-application/src/main/assembly/bin/linux-x86-64/sonar.sh
index 97d41beb93c..f77fa34f7a4 100755
--- a/sonar-application/src/main/assembly/bin/linux-x86-64/sonar.sh
+++ b/sonar-application/src/main/assembly/bin/linux-x86-64/sonar.sh
@@ -2,8 +2,24 @@
APP_NAME="SonarQube"
-# Java command location
-JAVA_CMD="java"
+# By default, java from the PATH is used, except if SONAR_JAVA_PATH env variable is set
+findjava() {
+ if [ -z "${SONAR_JAVA_PATH}" ]; then
+ if ! command -v java 2>&1; then
+ echo "Java not found. Please make sure that the environmental variable SONAR_JAVA_PATH points to a Java executable"
+ exit 1
+ fi
+ JAVA_CMD=java
+ else
+ if ! [ -x "${SONAR_JAVA_PATH}" ] || ! [ -f "${SONAR_JAVA_PATH}" ]; then
+ echo "File '${SONAR_JAVA_PATH}' is not executable. Please make sure that the environmental variable SONAR_JAVA_PATH points to a Java executable"
+ exit 1
+ fi
+ JAVA_CMD="${SONAR_JAVA_PATH}"
+ fi
+}
+
+findjava
# Get the fully qualified path to the script
case $0 in