声纳 MySQL 设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12355055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sonar MySQL setup
提问by Harvey
I just downloaded Sonar 3.2 and have configured the sonar.properties files to connect to my local MySql database. I have the following setting enabled:
我刚刚下载了 Sonar 3.2 并配置了 sonar.properties 文件以连接到我的本地 MySql 数据库。我启用了以下设置:
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
I am able to start the server without any errors and am able to log into the Sonar interface however when I run 'mvn sonar:sonar' on my maven project I get the following error:
我能够在没有任何错误的情况下启动服务器并且能够登录 Sonar 界面,但是当我在我的 Maven 项目上运行“mvn sonar:sonar”时,我收到以下错误:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project vrservices: Can not execute Sonar: Fail to connect to database: Cannot load JDBC driver class 'org.h2.Driver' -> [Help 1]
I have read a few forums that saying to put the following code in the settings.xml file however this still didn't fix the issue.
我读过一些论坛,说要将以下代码放在 settings.xml 文件中,但这仍然没有解决问题。
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- EXAMPLE FOR MYSQL -->
<sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8</sonar.jdbc.url>
<sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>root</sonar.jdbc.username>
<sonar.jdbc.password></sonar.jdbc.password>
</properties>
</profile>
I was wondering if anyone has come across this issue as well and if so how did you fix it?
我想知道是否有人也遇到过这个问题,如果有,你是如何解决的?
Thanks in advance!
提前致谢!
回答by Mark O'Connor
If you don't configure the Maven Sonar plugin, it will attempt to connect to the default location for the embedded database that ships with Sonar. Starting with version 3.2 the default embedded database is H2 (replacing derby).
如果您未配置 Maven Sonar 插件,它将尝试连接到 Sonar 附带的嵌入式数据库的默认位置。从 3.2 版开始,默认的嵌入式数据库是 H2(取代 derby)。
The forum recommendations are correct, I suspect that your Maven instance is not loading the correct settings file. Try running Maven as follows:
论坛的建议是正确的,我怀疑您的 Maven 实例没有加载正确的设置文件。尝试按如下方式运行 Maven:
mvn -s /path/to/settings/file/setting.xml sonar:sonar
回答by aditya
see that the attribute 'sonar.jdbc.url' in settings.xml and sonar.properties file are the same. secondly create a schema by name 'sonar' before you try to run the sonar server. good luck
看到 settings.xml 和 sonar.properties 文件中的属性 'sonar.jdbc.url' 是相同的。其次,在尝试运行声纳服务器之前,按名称“声纳”创建一个模式。祝你好运
回答by SevenEleven
Maybe you accidentally pasted the "profile" part to the wrong place in your settings.xml? Be sure to have it between the <profiles></profiles>
tags. (A colleague of mine just stumbled about a similar issue)
也许您不小心将“配置文件”部分粘贴到了 settings.xml 中的错误位置?一定要把它放在<profiles></profiles>
标签之间。(我的一个同事刚刚偶然发现了一个类似的问题)
回答by ZZ 5
Based on @Mark O'Connor answer: check if the file settings.xml is in right path (/home/YOURUSER/.m2/ or MAVEN_HOME environment variable) and that you run it from correct user - when I ran Sonar Maven Runner as root it couldn't the settings.xml file, because I had it in home folder of my user.
基于@Mark O'Connor 的回答:检查文件 settings.xml 是否在正确的路径(/home/YOURUSER/.m2/ 或 MAVEN_HOME 环境变量)中,并且您从正确的用户运行它 - 当我运行 Sonar Maven Runner 时root 它不能设置 settings.xml 文件,因为我把它放在我用户的主文件夹中。