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


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- && \
    unzip sonar-scanner-cli- && \
    mkdir /opt/sonar-scanner && \
    mv sonar-scanner-* /opt/sonar-scanner

ENV JAVA_HOME=/opt/sonar-scanner/jre

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
+ echo $JAVA_HOME
+ echo $PATH
+ java --version
openjdk 2022-02-08
OpenJDK Runtime Environment Temurin- (build
OpenJDK 64-Bit Server VM Temurin- (build, 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.