"Could not find ‘java’ executable in JAVA_HOME or PATH." when scanning with Scanner for NET

I had same problem with dotnet Your post helped me but now I have a problem with java :

  • dotnet tool install dotnet-sonarscanner --global
  • export PATH="$PATH:/root/.dotnet/tools"
  • dotnet sonarscanner begin /k:“test-test” /d:sonar.host.url=“http://localhost” /d:sonar.login=“token”
  • dotnet build
  • dotnet sonarscanner end /d:sonar.login=“token”

after las line i get:

$ dotnet sonarscanner end /d:sonar.login=“token”
SonarScanner for MSBuild 5.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI…
Could not find ‘java’ executable in JAVA_HOME or PATH.
The SonarScanner did not complete successfully
10:40:41.788 Post-processing failed. Exit code: 1
Cleaning up file based variables
ERROR: Job failed: exit code 1

Any suggestions??

@Andrei_Epure:
I use it in docker:
dotnet-sonarscanner -h:
SonarScanner for MSBuild 5.2
Using the .NET Core version of the Scanner for MSBuild

dotnet tool uninstall dotnet-sonarscanner --global
dotnet tool install dotnet-sonarscanner --global

Will it install sonarscanner with java??

@mickaelcaro I think that java is already installed on docker because when I exec “java -version” in docker bash i get:

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

but when .gitlab-ci.yml is executing I get this:

$ dotnet tool install --global dotnet-sonarscanner --global
 Tools directory '/root/.dotnet/tools' is not currently on the PATH environment variable.
 If you are using bash, you can add it to your profile by running the following command:
 cat << \EOF >> ~/.bash_profile
 # Add .NET Core SDK tools
 export PATH="$PATH:/root/.dotnet/tools"
 EOF
 You can add it to the current session by running the following command:
 export PATH="$PATH:/root/.dotnet/tools"
You can invoke the tool using the following command: dotnet-sonarscanner
 Tool 'dotnet-sonarscanner' (version '5.2.0') was successfully installed.
 $ java -version
 /bin/bash: line 106: java: command not found
Cleaning up file based variables
 ERROR: Job failed: exit code 1

@mickaelcaro I don’t have REPLY button to reply properly and I don’t know why :frowning:

Nope “$JAVA_HOME” returns me nothing

java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
export JAVA_HOME=/usr/bin/java
export PATH=$JAVA_HOME/bin:$PATH
$JAVA_HOME -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Hello @aksimoN

What OS are you using?

If on Linux, did you try out this answer:

Hi @aksimoN

This command line will install

  • The SonarScanner for .NET as a dotnet global tool
  • The underlying SonarScanner (java-based) is embedded with that

Specific JDK needs to be installed separately, we don’t embed it.

HTH,
Mickaël

1 Like

Hi @aksimoN

Please post answers along the way on this thread, otherwise with edits it’s hard to track.

Can you also try to echo the JAVA_HOME variable from your docker bash ? If it doesn’t exist, you should have it set up for the Scanner.

Mickaël