美文网首页
Could not find 'java' executable

Could not find 'java' executable

作者: 87d6dc4b11a7 | 来源:发表于2022-03-01 16:45 被阅读0次

    使用sonar-scanner执行代码扫描时,提示Could not find 'java' executable in JAVA_HOME or PATH。但是服务器已经配置过了JAVA_HOME。
    sonar-scanner使用的是自带的jre,进入/opt/sonar-scanner-4.6.2.2472-linux/bin目录,执行vi sonar-scanner查看。

    use_embedded_jre=true
    if [ "$use_embedded_jre" = true ]; then
      export JAVA_HOME="$sonar_scanner_home/jre"
    fi
    
    if [ -n "$JAVA_HOME" ]
    then
      java_cmd="$JAVA_HOME/bin/java"
    else
      java_cmd="`which java`"
    fi
    
    if [ -z "$java_cmd" -o ! -x "$java_cmd" ] ; then
      echo "Could not find 'java' executable in JAVA_HOME or PATH."
      exit 1
    fi
    

    因为我是从其他服务器拷贝过来的,经排查是权限不对,需要进行授权:

    [root@localhost ~]# cd /opt/sonar-scanner-4.6.2.2472-linux/bin/
    [root@localhost bin]# ./sonar-scanner -v
    Could not find 'java' executable in JAVA_HOME or PATH.
    [root@localhost bin]# cd ../jre/bin/
    [root@localhost bin]# ll
    总用量 16
    -rw-r--r-- 1 jenkins jenkins 12768 4月  20 2021 java
    [root@localhost bin]#
    [root@localhost bin]# chmod 755 java
    [root@localhost bin]#
    [root@localhost bin]# ll
    总用量 16
    -rwxr-xr-x 1 jenkins jenkins 12768 4月  20 2021 java
    [root@localhost bin]#
    [root@localhost bin]# ../../bin/sonar-scanner -v
    INFO: Scanner configuration file: /opt/sonar-scanner-4.6.2.2472-linux/conf/sonar-scanner.properties
    INFO: Project root configuration file: NONE
    INFO: SonarScanner 4.6.2.2472
    INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
    INFO: Linux 3.10.0-1160.el7.x86_64 amd64
    [root@localhost bin]#
    

    相关文章

      网友评论

          本文标题:Could not find 'java' executable

          本文链接:https://www.haomeiwen.com/subject/dezdrrtx.html