sonar+maven2使用说明

来源:互联网 发布:淘宝店铺最多几个客服 编辑:程序博客网 时间:2024/06/05 16:47

一、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中输入下面内容(直接用下面的内容覆盖原文件):  

 

<?xmlversion="1.0" encoding="UTF-8"?>

<settingsxmlns="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.0http://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&amp;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>

 

2、在项目源文件夹下,创建pom.xml文件,输入以下内容:

 

<projectxmlns="http://maven.apache.org/POM/4.0.0"

      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">

  <modelVersion>4.0.0</modelVersion>

 <groupId>com.maven</groupId><!--项目包路径-->

 <artifactId>maventest</artifactId><!--项目名称-->

 <name>maven@sonar--test</name><!--maven项目显示名称-->

 <url>http://maven.apache.org</url>

 <version>maven@sonar-test1.1</version><!--版本信息-->

  <build>

       <sourceDirectory>src</sourceDirectory><!--项目文件目录-->

       <outputDirectory>bin</outputDirectory><!--项目文件相关class文件目录-->

       <testSourceDirectory>test</testSourceDirectory><!--测试类文件目录-->

       <testOutputDirectory>bin</testOutputDirectory><!--测试类相关class文件目录-->

  <resources><!--项目资源文件目录-->

      <resource>

       <mergeId>resource-0</mergeId>

       <directory>src\resources</directory>

      </resource>

    </resources>

    <testResources><!--测试资源文件目录-->

      <testResource>

       <mergeId>resource-1</mergeId>

       <directory>test\resources</directory>

      </testResource>

    </testResources>

     <plugins>

  <plugin><!—解决覆盖率为0的问题-->

       <groupId>org.apache.maven.plugins</groupId>

       <artifactId>maven-surefire-plugin</artifactId>

        <version>2.3</version>

        <configuration>

          <includes>

           <include>**/*Test*.java</include>

          </includes>

        </configuration>

      </plugin>

<plugin><!—解决不支持泛型问题-->

       <groupId>org.apache.maven.plugins</groupId>

       <artifactId>maven-compiler-plugin</artifactId>

        <configuration>

          <source>1.5</source>

          <target>1.5</target>

        </configuration>

      </plugin>

</plugins>

</build>

  <properties>

   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!--字符集设置-->

  </properties>

  <dependencies>

    <dependency>

     <groupId>junit</groupId><!--单元测试依赖文件-->

     <artifactId>junit</artifactId>

      <version>3.8.1</version><!--单元测试版本-->

      <scope>test</scope>

    </dependency>

  </dependencies>

</project>

 

四、测试

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查看结果。

 

注:第一次运行的时候会很慢,它会去下载一些相应的依赖插件。

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小孩咳嗽两个月了还不好怎么办 生完小孩肚子瘦不下来怎么办 胆子小一个人在家里都害怕怎么办 怀了双胞胎两个宝宝很挤怎么办 飞机无人陪护如果接机延误该怎么办 过年要坐火车回家 狗狗怎么办 一岁八个月宝宝小腿弯怎么办 2岁宝不愿意坐马桶拉屎怎么办 宝宝两岁多肺炎出院还老咳嗽怎么办 去外国机场买机票不会说外语怎么办 坐飞机不能带的物品办理托运怎么办 深圳外地户口儿童要办身份证怎么办 网上订票错写了护照号怎么办 国航 在智能火车票订飞机票订反了怎么办 办社保卡的时候填错地址怎么办 两个人住酒店只有一张身份证怎么办 农村社保卡信息错了说改不了怎么办 社保卡与原医保卡信息错误怎么办 学校发的社保卡丢了怎么办 魔棒工具选中选区后再怎么办 微信每次打开都出现月球图案怎么办 仙人掌的刺扎手里弄不出来怎么办 保险交满15年领了一年死了怎么办 狗咬了出了点血怎么办 被小狗咬到了吃了海鲜怎么办 想给一个人道歉又不敢说怎么办 被尘封的故事中魔法师不见了怎么办 宝骏5602挡升3挡有点卡怎么办 剥开的榴莲没熟壳又扔了怎么办 视频播放器激活码设备超限了怎么办 ai如何把右边菜单栏隐藏了怎么办 矫正牙齿粘牙齿的胶掉了怎么办 3m双面胶生产的时候胶不干怎么办 新房赠送面积没地热想接地热怎么办 教育网注册报名的用户名忘了怎么办 艺术生校考通过文化没过本线怎么办 想做主持人 但不是播音专业怎么办 微信登录版本最低登录不上怎么办 所录微课的视频声音小是怎么办 电脑开机黑屏只有光标在闪怎么办 联想家悦重装系统时驱动缺失怎么办