您好,欢迎访问一九零五行业门户网

sonar+maven2使用说明

一、sonar环境搭建 1、安装jdk-1.5以上版本。 在环境变量中配置java_home,并在path里添加%java_home%\bin; 2、安装mysql-5.x以上版本。 3、mysql新建数据库并增加权限 createdatabase sonar character set utf8 collate utf8_general_ci; grant allon sonar.
一、sonar环境搭建1、安装jdk-1.5以上版本。在环境变量中配置java_home,并在path里添加%java_home%\bin;
2、安装mysql-5.x以上版本。3、mysql新建数据库并增加权限createdatabase sonar character set utf8 collate utf8_general_ci;
grant allon sonar.* to sonar@localhost identified by ‘sonar’;
flush privileges ;
4、在sonar官网www.sonarsouce.org上下载并解压sonar-2.8.zip,不要放在中文目录下。5、配置sonar-2.8\conf\sonar.properties文件:1)配置启动的http端口sonar.web.host:                           localhost
sonar.web.port:                           9000
sonar.web.context:                        /
三句前本来被注释,取消注释
2)注释掉derby数据库绑定(49、50行)#sonar.jdbc.url:                           jdbc:derby://localhost:1527/sonar;create=true
#sonar.jdbc.driverclassname:               org.apache.derby.jdbc.clientdriver
3)取消mysql连接的注释#-----mysql 5.x/6.x
# comment theembedded database and uncomment the following properties to use mysql. thevalidation query is optional.
sonar.jdbc.url:                        jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8
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配置有关
第三条,也就是说,把sonar.properties 文件修改成以下内容:
# listenhost/port and context path (for example / or /sonar). default values arelocalhost:9000/.
sonar.web.host:                           localhost
sonar.web.port:                           9000
sonar.web.context:                        /
sonar.jdbc.username:                       sonar
sonar.jdbc.password:                       sonar
#-----mysql 5.x/6.x
# commentthe embedded database and uncomment the following properties to use mysql. thevalidation query is optional.
sonar.jdbc.url:                           jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8
sonar.jdbc.driverclassname:                com.mysql.jdbc.driver
sonar.jdbc.validationquery:                select 1
#-----connection pool settings
sonar.jdbc.maxactive:                      10
sonar.jdbc.maxidle:                        5
sonar.jdbc.minidle:                        2
sonar.jdbc.maxwait:                        5000
sonar.jdbc.minevictableidletimemillis:     600000
sonar.jdbc.timebetweenevictionrunsmillis:  30000
二、maven环境搭建 1、到maven官网http://maven.apache.org/download.html去下载maven2.x版本。解压文件到非中文目录下。 2、配置maven_home环境变量,在path里添加%maven_home%\bin;在命令行输入mvn –h测试maven环境是否配置正确。   配置正确后,开始使用。
三、maven+sonar测试1、在%maven_home%\conf\setting.xml中输入下面内容(直接用下面的内容覆盖原文件):
xmlns:xsi=http://www.w3.org/2001/xmlschema-instance
          xsi:schemalocation=http://maven.apache.org/settings/1.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd>
sonar
true
jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8
com.mysql.jdbc.driver
               sonar
               sonar
http://localhost:9000
2、在项目源文件夹下,创建pom.xml文件,输入以下内容: 
      xmlns:xsi=http://www.w3.org/2001/xmlschema-instance
      xsi:schemalocation=http://maven.apache.org/pom/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd>
  4.0.0
 com.maven
 maventest
 maven@sonar--test
 http://maven.apache.org
 maven@sonar-test1.1
src
       bin
       test
       bin
resource-0
       src\resources
resource-1
       test\resources
org.apache.maven.plugins
       maven-surefire-plugin
        2.3
**/*test*.java
org.apache.maven.plugins
       maven-compiler-plugin
1.5
          1.5
utf-8
junit
     junit
      3.8.1
      test
四、测试1、先运行%sonar_home%\bin\windows-x86-32\stopntservice.bat(如果是第一次使用)
2、启动sonar在%sonar_home%\bin\windows-x86-32\startsonar.bat,等到启动完成,进入下一步
3、在命令行进入到项目文件的目录中去,然后再输入mvn sonar:soanr进行测试
4、在浏览器中输入http://localhost:9000查看结果。
注:第一次运行的时候会很慢,它会去下载一些相应的依赖插件。
其它类似信息

推荐信息