Fedora 34 - CLI 4.7.0 - Could not find 'java' executable in JAVA_HOME or PATH

Hi,

As has been reported on similar threads here I’m running into the “Could not find ‘java’ executable in JAVA_HOME or PATH.” issue with sonarscanner cli tool. The underlying OS is fedora 34 running in a docker container. The binaries are from the 4.7.0 release with the bundled JRE.

FROM fedora:34

RUN dnf install -y wget unzip && \
    wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip && \
    unzip sonar-scanner-cli-4.7.0.2747-linux.zip && \
    mkdir /opt/sonar-scanner && \
    mv sonar-scanner-4.7.0.2747-linux/* /opt/sonar-scanner

ENV JAVA_HOME=/opt/sonar-scanner/jre
ENV PATH="$JAVA_HOME/bin:${PATH}"

Inside this container the following script is being run, additional commands were added to aid with debug.

+ stat -c '%a %n' /opt/sonar-scanner/jre/bin/java
755 /opt/sonar-scanner/jre/bin/java
+ ls -l /opt/sonar-scanner/jre/bin
total 16
-rwxr-xr-x. 1 root root 12768 Feb  8 16:49 java
+ ls /opt/sonar-scanner/jre/bin
java
+ echo $JAVA_HOME
/opt/sonar-scanner/jre
+ echo $PATH
/opt/sonar-scanner/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ java --version
openjdk 11.0.14.1 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)
+ /opt/sonar-scanner/bin/sonar-scanner -X -e -Dsonar.login=<login>
Could not find 'java' executable in JAVA_HOME or PATH.

So far the pathing seems correct, both ENV variables have been setup, permissions seem ok, java can be run fine outside the sonar-scanner. Wondering what else to try. Thanks

Hey there.

JAVA_HOME should point to the folder the executable is in (/jre/bin/) rather than the folder aabove.

But there’s really no reason you should need to set this at all. What made you decide you needed to?

Be aware that there’s also a sonar-scanner-cli docker image.

I’ve tried the paths a few different ways. The sonar-scanner-cli docker image works nicely for other languages we’ve integrated with but hasn’t worked out for C++. This note also made me think it wasn’t a great idea:

NB: These Docker images are not compatible with C/C#/C++/Objective-C projects.

While I can run the scanner with the docker image the project breaks in other ways due to different build environments.