2014-01-08 50 views
3

我正在慢慢生氣。Sonar Runner:Windows 7:開始時針對jdbc拋出錯誤

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

我已經SonarQube運行鍼對端口號爲9000

當我嘗試運行聲納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文件非常簡單。

任何意見將不勝感激。

感謝您的閱讀。

+0

爲了找到您的JAR,它必須位於classpath中。看起來你正在使用某種.BAT文件來執行這個程序。我會從那裏開始,看看它是否定義了某種CLASSPATH變量。 – CodeChimp

回答

0

我在使用Linux Mint Debian Edition的Jenkins設置中發生了同樣的錯誤消息。我用SonarQube亞軍2.3和SonarQube服務器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服務器,它解決了這個問題對我來說。

我知道這是微不足道的,但這就是我的情況,它很容易忽略小事情。

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 

最後兩行代碼沒有在Mysql的任何sonar教程中指定。

最後確保您創建了具有適當值的SONAR_RUNNER_HOME並將路徑變量條目創建到bin目錄。