Sonar配置,严格按步骤做下来,一定可以的

环境前提:安装java(JAVA_HOME, PATH), 我使用jdk8(64位)。系统为win7(64) 。实验需要验证的项目为一般java web项目(我命名之TEST项目),直接通过.classpath组织lib,未使用maven/git等手段。
1、下载SonarQube:sonarqube-4.5.7 (http://www.sonarqube.org/downloads/ 点击 Show all versions ),解压。
2、建立mysql库:(我用的版本:5.5, 各位照抄)
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;
3、修改sonarqube的配置:\sonarqube-4.5.7\conf\sonar.properties(如果第2步照抄了,就这三行,其他的不要动)
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
4、启动SonarQube, \sonarqube-4.5.7\bin\windows-x86-64\StartSonar.bat(双击,等着,看到:Process[web] is up,就是成功了,这个窗口不要关闭)访问:http://localhost:9000查看结果。
5、下载:sonar-runner-2.4。(http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip),解压(我放在E:\tool\sonar-runner-2.4\
6、sonar-runner-2.4中查找并修改sonar-runner.properties(如果第2、3步骤,您都抄了的话,这里您也不用动)
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- Default source code encoding
#sonar.sourceEncoding=UTF-8
#----- Security (when 'sonar.forceAuthentication' is set to 'true')
#sonar.login=admin
#sonar.password=admin
7、将E:\tool\sonar-runner-2.4\bin(就是解压路径,自己看着改吧)设置到系统环境变量path中(参考java_home, path的设置)
8、在您需要验证的项目(前面说到的TEST项目)的根目录下(.project文件同目录)添加文档:sonar-project.properties(需要改的部分红色标出,您的目录不可能和我一样吧,这里您一定要改的)
# Required metadata
sonar.projectKey=TEST
sonar.projectName=TEST
sonar.projectVersion=1.0
# Path to the parent source code directory.
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional. If not set, SonarQube starts looking for source code
# from the directory containing the sonar-project.properties file.
sonar.sources=java/src
sonar.libraries=WebRoot/WEB-INF/lib
# Encoding of the source code
sonar.sourceEncoding=UTF-8
# Additional parameters
sonar.my.property=value
9、FDS根目录下,执行:sonar-runner,等着。成功结束的话(我执行过程中遇到max_allowed_packet问题,mysql管理员执行SET GLOBAL max_allowed_packet = 2*1024*1024*10 重启后解决,一般性,各位遇不到,就不特殊说了),访问:http://localhost:9000。  
登录用户名 admin:admin。 查看结果。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值