Sonar Runner:Windows 7:启动时针对jdbc抛出错误

3

我正在慢慢变得疯狂。

我使用的是最新的SonarQube和runner 2.3,操作系统为Windows 7 64位。

SonarQube运行在9000端口。

当我尝试运行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

我不知道为什么它找不到。
我的.properties文件相当简单。
任何建议都将不胜感激。
谢谢阅读。

为了让你的JAR文件被找到,它必须在类路径中。看起来你正在使用某种.BAT文件来执行这个程序。我建议从那里开始,看看它是否定义了CLASSPATH变量。 - CodeChimp
2个回答

0
如果你正在尝试使用本地的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

在所有 Sonar 的 Mysql 教程中都没有提到最后两行代码的具体含义。

最后,请确保您已经创建了具有正确值的 SONAR_RUNNER_HOME,并且将路径变量条目加到了 bin 目录中。


0

我在我的使用Linux Mint Debian Edition的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

这里我读到了重启SonarQube服务器的方法,这解决了我的问题。

我知道这很琐碎,但在我的情况下就是这样,而且很容易忽略细节问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接