【问题标题】:Sonar Runner : Windows 7 : Throwing error against jdbc on startSonar Runner:Windows 7:在启动时对 jdbc 抛出错误
【发布时间】:2014-01-08 19:31:35
【问题描述】:

我要慢慢发疯了。

我在 Windows 7 64 位上,使用最新的 SonarQube 和 runner 2.3。

我在 9000 端口上运行 SonarQube。

当我尝试运行 sonar-runner.bat 时,我得到:

C:\myRoot\SonarQube\SonarQubeRunner\sonar-runner-dist-2.3\sonar-runner-2.3
SonarQube Runner 2.3
Java 1.7.0_45 Oracle Corporation (64-bit)
Windows 7 6.1 amd64
INFO: Runner configuration file: C:\myRoot\SonarQube\SonarQubeRunner\sonar-runner-dist-2.3\sonar-runner-2.3\conf\sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Work directory: C:\myRoot\SonarQube\sonar_examples\sonar-examples-master\projects\languages\php\php-sonar-runner\src\.sonar
INFO: SonarQube Server 4.0
14:18:52.103 INFO  - Load batch settings
14:18:52.196 INFO  - User cache: C:\Users\myName\.sonar\cache
14:18:52.212 INFO  - Install plugins
14:18:52.602 INFO  - Install JDBC driver
14:18:52.602 INFO  - Create JDBC datasource for jdbc:mysql://localhost:3306/sonar
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 1.700s
Final Memory: 4M/74M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: Fail to connect to database
ERROR: Caused by: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
ERROR: Caused by: com.mysql.jdbc.Driver
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

当我收集调试信息时,我得到:

        yadda, yadda ...
        ... 32 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
        ... 37 more

我有一个名为 mysql-connector-java-5.1.26.jar 的文件:

C:\myRoot\SonarQube\sonarqube-4.0\sonarqube-4.0\extensions\jdbc-driver\mysql

我想不出为什么找不到它。

我的 .properities 文件相当简单。

任何建议将不胜感激。

感谢阅读。

【问题讨论】:

  • 为了找到您的 JAR,它必须位于类路径中。看起来您正在使用某种 .BAT 文件来执行此程序。我会从那里开始,看看它是否定义了某种 CLASSPATH 变量。

标签: java windows sonarqube sonar-runner


【解决方案1】:

我在使用 Linux Mint Debian 版的 Jenkins 设置中遇到了同样的错误消息。我使用了 SonarQube Runner 2.3 和 SonarQube Server 4.1.1

ERROR: Unable to execute SonarERROR: Caused by: Fail to connect to database
ERROR: Caused by: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
ERROR: Caused by: com.mysql.jdbc.Driver

Here我读了重启SonarQube服务器,解决了我的问题。

我知道这是微不足道的,但就我而言,这就是它的全部内容,而且很容易忽略这些小事。

【讨论】:

    【解决方案2】:

    如果您尝试使用本地 Mysql 数据库,请在 sonarcube 的 sonar.properties 文件中使用这些代码。

    # Permissions to create tables, indices and triggers must be granted to JDBC user.
    # The schema must be created first.
    sonar.jdbc.username=root
    sonar.jdbc.password=root
    
    #----- MySQL 5.x
    # Comment the embedded database and uncomment the following line to use MySQL
    sonar.jdbc.url=jdbc:mysql://localhost:3306/sonardb?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
    sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
    sonar.jdbc.validationQuery: select 1
    

    Mysql 的任何声纳教程中都没有指定最后两行代码。

    最后确保您创建了具有正确值的 SONAR_RUNNER_HOME 和 bin 目录的路径变量条目。

    【讨论】:

      猜你喜欢
      • 2016-12-23
      • 2016-06-15
      • 2016-07-17
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      相关资源
      最近更新 更多