Could not find 'java' executable in JAVA_HOME

Hi,

I am encountering the below issue on CentOS Linux release 7.9.2009 (Core)

java -version

openjdk version “11.0.9.1” 2020-11-04 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.9.1+1-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.9.1+1-LTS, mixed mode, sharing)
(reverse-i-search)`son’: stat /opt/scannerdir/^Cnar-scanner-4.5.0.2216-linux/jre/bin/java

echo $JAVA_HOME

/usr/lib/jvm/java-11-openjdk-11.0.9.11-2.el7_9.x86_64

sonar-scanner

Could not find ‘java’ executable in JAVA_HOME or PATH.

Any clue? Thanks in advance. I look forward to hearing from you. Please let me know if you need any additional information.

Best Regards,

Kaushal

Hi Kaushal, welcome to the SonarSource Community!

It appears based on your pasted output that you downloaded the version of sonar-scanner that includes an embedded JRE yet you also have a separate JDK already installed. In this case, you may wish to use the sonar-scanner zip install that does not bundle another JRE.

Yet still, it should have succeeded. How exactly did you invoke sonar-scanner and from which directory? Did you add its bin directory to your PATH first as our docs suggest? Is it being invoked directly or within another shell or script of some kind?

+1 on this.

I have the same issue on Ubuntu 18.04.5 LTS

java -version
openjdk version “1.8.0_282”
OpenJDK Runtime Environment (build 1.8.0_282-8u282-b08-0ubuntu1~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)

echo $JAVA_HOME
/usr/local/java/jre1.8.0_281/bin

sonar-scanner
“Could not find ‘java’ executable in JAVA_HOME or PATH.”

I’m invoking sonar-scanner directly from the top level dir of my repo, and I have added the sonar-scanner bin dir to my PATH. No luck.

Any help would be great.
Thanks

Turns out the error message is misleading. The real problem is the java executable that is included in sonar-scanner-#.#.#.####-linux/jre/bin/ needs execute permissions set. After running

chmod 755 .../sonar-scanner-#.#.#.####-linux/jre/bin/java

sonar-scanner was able to scan.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.