Can't find Java

We have installed a private build server for Azure DevOps. We use SonarCloud build tasks. Run the code Run Code Analysis task is run, I get the following errors. JAVA_HOME is defined and the path has %JAVA_HOME%\bin in it.

[command]C:\agent_work_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.7.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end

SonarScanner for MSBuild 4.6.2

Using the .NET Framework version of the Scanner for MSBuild

Post-processing started.

13:23:34.173 13:23:34.173 WARNING: Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage.

WARNING: File ‘C:\agent_work\1\s\EnrollmentServices\Properties\PublishProfiles\InternalServices-UAT - FTP.pubxml’ does not exist.

Calling the SonarQube Scanner…

ERROR: JAVA_HOME not found in your environment, and no Java

executable present in the PATH.

Please set the JAVA_HOME variable in your environment to match the

location of your Java installation, or add “java.exe” to the PATH

##[error]The SonarQube Scanner did not complete successfully

The SonarQube Scanner did not complete successfully

##[error]13:23:34.564 Post-processing failed. Exit code: 1

13:23:34.564 Post-processing failed. Exit code: 1

##[error]C:\agent_work_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.7.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe failed with return code: 1

##[section]Finishing: Run Code Analysis


2 things :

  • Are you sure that the environment variable is visible by the account that runs the agent ? If no, set it system-wide or specify it for this account as well.
  • When you go to Project Settings -> Agent Pool -> -> , in the capabilities tab, do you see the JAVA_HOME set ? If not and point above has been verified, you can try yo reconfigure your local agent by issuing .\config.cmd remove then .\config.cmd so i might scan newest env variables and then you should be good to go.


1 Like

As a last resort I rebooted the server and it was ok. It would appear the previous settings were cached or something.

Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you
are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

Hi @mickaelcaro

Im having the same issues with sonar_scanner in Azure DevOps…
I have a reference setup to JAVA_HOME and also in Path but am always getting errors saying that Java home can not be found

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

In your reply above you mention issuing .\config.cmd remove … what config file are you refering to ? I can not see this file in the scanner package. I have also tried stopping the agent and starting again…

Hi, the .config.cmd file is the config file of the build agent, located in the root folder of its installation path.


God bless you