5

I've been trying to configure sonarqube to work with cloud build trigger and want to use bitnami's sonarqube compute instance installation but when I installed sonar-scanner using this guide: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/ and when run sonar-scanner -h I receive this Error "Could not find 'java' executable in JAVA_HOME or PATH" my JAVA_HOME is opt/bitnami/java and PATH is opt/bitnami/java/bin help me what I'm doing wrong or if missing something.

Rehan
  • 408
  • 1
  • 6
  • 17

6 Answers6

8

Independent of your JAVA_HOME, sonar-scanner uses its own JRE, which requires authorization:

chmod 755 ...sonar-scanner-4.3.0.2102-linux/jre/bin/java
Tim Meyer
  • 12,210
  • 8
  • 64
  • 97
林万程
  • 351
  • 3
  • 9
3

I had the same error: Could not find 'java' executable in JAVA_HOME or PATH.

The scanner use own java bin file and you should change it.

  1. Open a folder where is your unzipped sonar scanner.

There is ./jre/bin directory.

For example, my sonar scanner is /opt/sonar-scanner/, then my folder with java is /opt/sonar-scanner/jre/bin/.

  1. Delete that java file.

  2. Make a symlink the original java to run from the folder.

Example:

ln -s /usr/bin/java /opt/sonar-scanner/jre/bin/java

Done.

2

Bitnami developer here,

The following commands worked for me on a GCE instance:

  • Download solr-scanner 4.2.0:

  • Unzip it in /opt:

sudo unzip -d /opt sonar-scanner-cli-*.zip
  • Download sonar-scanning-examples:

  • Unzip them in $HOME/sonar-scanning-examples:

unzip -d $HOME master.zip
cd /home/bitnami/sonar-scanning-examples-master/sonarqube-scanner
  • Analyze a project as shown below. Replace the PASSWORD placeholder with the correct password.
/opt/sonar-scanner-*/bin/sonar-scanner -Dsonar.login=admin -Dsonar.password=PASSWORD

In case you face some issue, try to load the environment before analyzing the project:

sudo /opt/bitnami/use_sonarqube

I hope it helps

David Gomez
  • 644
  • 5
  • 9
1

Had this issue on Mac OS. This thread helped to solve my issue.

The variable $JAVA_HOME should point to the main directory of java, where the bin folder can be found by appending bin.

So in my case I had extra bin in the path.

Ned
  • 1,378
  • 16
  • 28
0

Had the same issue on my macos When I tried executing the command sonar-scanner -h then I tried below several methods :

1.Check for the path if you have included that or not in the bash_profile

Steps :

Step 1 : Open a terminal on macos and then write the below command to check if you have setup all the paths correctly.

nano ~/.bash_profile

Step 2: Check for all the paths in the bash_profile file if not added then add all the below paths :

export SONAR_HOME=/path/to/your/sonarqube/sonarqube-version/bin/macosx-universal-64
export JAVA_HOME=/path/on/your/local/machine/where/java/installed
export PATH=$JAVA_HOME/bin:$PATH
export SONAR=$SONAR_HOME/bin
export PATH=$SONAR:$PATH
export PATH="/path/to/your/sonar-scanner/on/localmachine/sonar-scanner-4.8.0.2856-macosx/bin:$PATH"

Step 3: Then check for the JAVA_HOME path by typing below command in new terminal

echo $JAVA_HOME 

If that prints nothing then you need to check for the correct absolute path on your local machine If all above steps you have done correctly and still you are getting error then you need to check for the permissions :

Execute the below command :

chmod +x /path/to/your/sonar-scanner/on/localmachine/sonar-scanner-version/bin/sonar-scanner

And then check by directly executing below command if you are still getting error or not by directly executing the sonar-scanner -h command with absolute path :

/path/to/your/sonar-scanner/on/localmachine/sonar-scanner-4.8.0.2856-macosx/bin/sonar-scanner -h

If above command ran successfully then it should run the sonar-scanner -h command too without giving "Could not find 'java' executable in JAVA_HOME or PATH"error Also make sure that you have allowed the java jdk to run on your local machine -> Go to System Preferences... > Security & Privacy and there should be a button saying Open Anyway, under the General tab.

Another possible reason of getting error could be that you have mutliple jdk installed. If that is the case then remove all the older versions of jdk.

Jyotsana
  • 1
  • 2
0

if you want to run a docker image of bitnami you should run it with privileged flag.

docker run --privileged -i dockerimagename

i faced the same problem on Centos7 and that was my solution. hope it helps!

chondroboy
  • 156
  • 2