安装并配置sonar

借鉴了一下网上资源哈:
一、sonar环境搭建(前提是JDK-1.5x以上版本和mysql-5.x以上版本已经成功安装)
1、mysql新建数据库并增加权限

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

GRANT all ON sonar.* TO sonar@localhost IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES ;

2、在sonar官网www.sonarsouce.org上下载并解压sonar-3.3.2.zip,不要放在中文目录下。
3、配置sonar-3.3.2\conf\sonar.properties文件。

1)配置启动的http端口
# Listen host/port and context path (for example / or /sonar). Default values are 0.0.0.0:9000/.
sonar.web.host: localhost
sonar.web.port: 9000
sonar.web.context: /

三句前本来被注释,取消注释就可以啦
2)取消mysql连接的注释
#----- MySQL 5.x/6.x
# Comment the embedded database and uncomment the following properties to use MySQL. The validation query is optional.
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true

sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
sonar.jdbc.validationQuery: select 1

运行sonar-2.8\bin\windows-x86-32\StartSonar.bat,打开相应的网页:http://localhost:9000测试是否配置成功,这里的页面链接跟前头的http配置有关

二、maven环境搭建
1、到maven官网http://maven.apache.org/download.html去下载maven2.x版本。解压文件到非中文目录下。
2、配置MAVEN_HOME环境变量,在path里添加%MAVEN_HOME%\bin;在命令行输入mvn –h测试MAVEN环境是否配置正确。
配置正确后,开始使用。

三、maven配置
1、在%MAVEN_HOME%\conf\setting.xml中输入下面内容(直接用下面的内容覆盖原文件):

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<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.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>

<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>

四、myeclipse配置
1、Myeclipse 8.5本身已经集成了maven插件,修改maven的私服文件位置
Window -> preferences -> myeclipse --> maven4myeclipse --> maven --> installations --> add --> 选择你的maven解压目录。
Window -> preferences -> myeclipse --> maven4myeclipse --> maven --> user settings -->选择刚才编辑的文件%MAVEN_HOME%\conf\settings.xml

2、在myeclipse中file-->new-->other-->myeclipse-->java maven project,项目中会自动生成maven的配置文件pom.xml,不需要再去配置这个文件,只要自己去写自己的项目文件就行。

五、测试
1、启动sonar在%SONAR_HOME%\bin\windows-x86-32\StartSonar.bat,等到启动完成,进入下一步
2、在命令行进入到项目文件的目录中去,然后再输入mvn sonar:soanr进行测试
3、在浏览器中输入http://localhost:9000查看结果。这时就可以看到代码覆盖率和代码测试用例的统计数据了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值