视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
sonar+maven2使用说明
2020-11-09 08:10:14 责编:小采
文档


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

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

下载本文
显示全文
专题