Jenkins Sonarqube Plugin: JAVA_HOME exists but does not point to a valid Java home

12.8k views Asked by At

I am trying to set up the Sonarqube for my project, but when I start to generate a build, I get the following error:

ERROR: JAVA_HOME exists but does not point to a valid Java home
   folder. No "\bin\java.exe" file can be found there.

The SonarQube Scanner did not complete successfully

I check some docs but none of them helps. For the JAVA_HOME environment variable, I point it to be C:\Program Files (x86)\Java\jdk1.8.0_111 I also double check it by using powershell java -version command. It also gives me the same answer: java version "1.8.0_111" . Anyone knows how to solve the problem?

Thanks.

8

There are 8 answers

0
Srinivas Charan Mamidi On

Ensure that JAVA_HOME is pointing JDK .

0
Ankit Gupta On

Please try to reinstall the java 8. Setup JAVA_HOME again then It will work. This problem might be because space between "Program Files (x86)"

0
Elviss Strazdins On

if EXIST in the sonar-scanner.bat fails because there is a space in the path, so the solution is to set the JAVA_HOME to a value without spaces e.g. using the short name of the "Program Files" SET JAVA_HOME= C:\Progra~1\Java\jre9

0
sunigos On

I had the same problem and struggled with it for a while. After modifying sonar-scanner.bat a bit I found out that during execution of Sonarqube the %JAVA_HOME% was completely different from the one I configured in my environment variables. Turned out I had hardcoded JDK installations in my Global Tool Configuration inside Jenkins.

My solution:

  1. Open your Jenkins, go to Manage Jenkins -> Global Tool Configuration
  2. Click JDK installations...
  3. Make sure JAVA_HOME parameter is empty or just click Delete JDK

In this case Jenkins will use %JAVA_HOME% variable it finds during the execution and it's just the one you configured in your environment variables. Worked for me

0
jeff porter On

You can edit:

C:\Users\HOME_FOLDER\.jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\SonarQubeScanner\bin>notepad sonar-scanner.bat

and put following:

SET JAVA_HOME=< JDK Path>

0
Govardhan S On

I encountered the same error. The issue was with sonar-scanner.bat referencing wrong %JAVA_HOME% path.
In the sonar-scanner.bat the variable "use_embedded_jre" is set to true and immediately the validation is done for the PATH.

@REM ==== START VALIDATION ====
@REM *** JAVA EXEC VALIDATION ***

set use_embedded_jre=true
if "%use_embedded_jre%" == "true" (
  set "JAVA_HOME=%SONAR_SCANNER_HOME%\jre"
)

Set the variable value to "false", the issue will be fixed.

set use_embedded_jre=false
0
Manoj Patil On

You should restart your machine after java installation.

0
LP13 On

I was having the same issue. On my machine JRE was located at C:\Program Files (x86)\Jenkins\jre. So I appended System's PATH Environment Variable with C:\Program Files (x86)\Jenkins\jre\bin;

It worked.

Do not forget to restart Jenkins service from Windows Services