# Dotnet-sonarscanner - fails on post-processing - “Could not find or load main class”

using the dotnet-sonarscanner version 4.7.1 through the command line

trying to get the sonar scanner running from the command line at the moment with just msbuild.exe solution.sln /rebuild it’s currently failing on the post-processing step and i can’t seem to get beyond that

I thought maybe having spaces in my java path was causing the problem so I tried updating my path to a location that didn’t have any spaces in it but no luck.

I also tried using dotnet sonar scanner and msbuild sonar scanner. both with the same result

These are the steps i’m executing:

dotnet-sonarscanner begin /k:"key" /d:sonar.host.url="https://my_company_sonarqube.com" /d:sonar.login="token" /d:sonar.verbose=true

MSBuild.exe solution.sln /t:Rebuild /p:Platform="Any CPU"



Everything seems to work fine until i get to the post-processing step:

Executing file C:\Users\userid\.dotnet\tools\.store\dotnet-sonarscanner\4.7.1\dotnet-sonarscanner\4.7.1\tools\netcoreapp2.1\any\sonar-scanner-4.1.0.1829\bin\sonar-scanner.bat
Args: -Dsonar.scanAllFiles=true -Dproject.settings=C:\Users\userid\Documents\project_path\.sonarqube\out\sonar-project.properties --embedded --debug <sensitive data removed>
Working directory: C:\Users\userid\Documents\project_path
Timeout (ms):-1
Process id: 38116
Error: Could not find or load main class
Process returned exit code 1
The SonarQube Scanner did not complete successfully
19:53:44.155  Post-processing failed. Exit code: 1


Hi,

Do you have some kind of debug log or this is the only trace you get from the output ?

Thank you.

I turned on /d:sonar.verbose=true in the begin statement and piped everything to a file. I have quite a bit of output from that. Is there another place I can look for debugging information?

Normally you should have everything output in the console.

Which version of JDK do you have installed and running the scanner with ?

Using the following JDK

java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)


In the output file that you have, do you have a stack trace after the error message ? If yes can you send it here or via PM ?

Thanks.

there is no more output after the Post-processing failed. Exit code: 1

is there a way to add more debugging information. it seems like java is complaining

Can you try to re-issue the sonar-scanner-4.1.0.1829\bin\sonar-scanner.bat commandline directly with the arguments quoted just below to see if you get any extra log ? Seems weird that we don’t have the main class name that fails to load.

ok this is what i get when i run the batch script directly. i also set echo on in the script

i’m pretty sure it can’t find org.sonarsource.scanner.cli.Main in \lib\sonar-scanner-cli-4.1.0.1829.jar

C:\Users\userid\Documents\project_path>"C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe" -Djava.awt.headless=true -Xdebug "" -cp "C:\Users\userid\.dotnet\tools\.store\dotnet-sonarscanner\4.7.1\dotnet-sonarscanner\4.7.1\tools\netcoreapp2.1\any\sonar-scanner-4.1.0.1829\bin\..\lib\sonar-scanner-cli-4.1.0.1829.jar" "-Dscanner.home=C:\Users\userid\.dotnet\tools\.store\dotnet-sonarscanner\4.7.1\dotnet-sonarscanner\4.7.1\tools\netcoreapp2.1\any\sonar-scanner-4.1.0.1829\bin\.." "-Dproject.home=C:\Users\userid\Documents\project_path" org.sonarsource.scanner.cli.Main -Dsonar.scanAllFiles=true -Dproject.settings=C:\Users\userid\Documents\project_path\.sonarqube\out\sonar-project.properties --embedded --debug
Error: Could not find or load main class

C:\Users\userid\Documents\project_path>if ERRORLEVEL 1 goto error
C:\Users\userid\Documents\project_path>set ERROR_CODE=1
C:\Users\userid\Documents\project_path>goto exit
C:\Users\userid\Documents\project_path>call :returncode 1
C:\Users\userid\Documents\project_path>exit /B 1
C:\Users\userid\Documents\project_path>


Hi,

Can you very that the JAR \lib\sonar-scanner-cli-4.1.0.1829.jar is not altered? Check its size, and if you can unzip it. You can also compute its hash (md5 or sha1) so that we could compare.
In the past I remember some very aggressive anti-virus software having corrupted our files.

Can you also give us the output of:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe -version

Thanks

So i just have JRE 8. do i need to upgrade to jre 11 or get the jdk?

here is the sha1 for the jar. i unzipped and org.sonarsource.scanner.cli.Main is definitely there :

Name: sonar-scanner-cli-4.1.0.1829.jar
Size: 641359 bytes (626 KiB)
SHA1: 8B553DC2748A6CB36EB4BE42C6DFC8D3FA6F0A37


Java 8 is fine (sorry, I missed your previous post mentioning it), no need to upgrade. The sha1 looks good as well.

Can you try to run the command directly:
"C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe" -Djava.awt.headless=true -Xdebug "" -cp "C:\Users\userid\.dotnet\tools\.store\dotnet-sonarscanner\4.7.1\dotnet-sonarscanner\4.7.1\tools\netcoreapp2.1\any\sonar-scanner-4.1.0.1829\bin\..\lib\sonar-scanner-cli-4.1.0.1829.jar" "-Dscanner.home=C:\Users\userid\.dotnet\tools\.store\dotnet-sonarscanner\4.7.1\dotnet-sonarscanner\4.7.1\tools\netcoreapp2.1\any\sonar-scanner-4.1.0.1829\bin\.." "-Dproject.home=C:\Users\userid\Documents\project_path" org.sonarsource.scanner.cli.Main -Dsonar.scanAllFiles=true -Dproject.settings=C:\Users\userid\Documents\project_path\.sonarqube\out\sonar-project.properties --embedded --debug

There is maybe an escaping problem, either because of a space, or maybe because of another character.

ok running the java command directly produced the same result, that is

Error: Could not find or load main class

i also tried cleaning up the paths a bit and removing relative references. no luck

Can you try this overly simplified call?

cd "C:\Users\userid\.dotnet\tools\.store\dotnet-sonarscanner\4.7.1\dotnet-sonarscanner\4.7.1\tools\netcoreapp2.1\any\sonar-scanner-4.1.0.1829\lib"
java -cp sonar-scanner-cli-4.1.0.1829.jar org.sonarsource.scanner.cli.Main


ok so i’m not sure why i was getting the main class error, but it looks like my problem was not having my ssl certificates for the sonarqube server. Starting over and setting SONAR_SCANNER_OPTS seemed to do the trick.

set SONAR_SCANNER_OPTS =  "-Djavax.net.ssl.trustStore="C:\path\to\trustStore"