序目
-
Eclipse IDE开发环境
-
Maven构建自动化编译打包项目
-
Nexus 私有Maven仓库
-
SVN源码管理
-
junit+mockito 单元测试与mock框架
-
集成 JaCoCo分析单元测试的覆盖率
-
Jenkins集成
-
Sonar分析源代码质量
-
Glassfish Web容器发布
人人都在谈敏捷开发的时代,所谓工欲善其事必先利其器……在此之前得有jdk环境,在这不多说了。
Maven构建自动化编译打包项目
如果在服务器上配置编译环境,只需要下截一个免安装的maven运行包,解压后设置环境变量便可使用。
如果在eclipse下就不需要了,因为eclipse已集成了maven环境。
Eclipse IDE开发环境
用eclipse 建立maven project后,在eclipse上调试,我是用jetty来跑开发环境,因为jetty是个较轻量级的web容器,在开环境里占用的资源相对少些,开发过程中会同时用到多种软件,机器上资源得省则省。有人会问我:“为何不用Myeclipse? ” 我会答:“老大,Myeclipse是商业软件,收费的呀!”
eclipse + maven + jetty 的热布署参考:http://blog.csdn.net/esinzhong/article/details/26070723
Maven 集成jacoco分析单测试的覆盖率
在父项目的pom.xml上加入如下配置
<build>
<plugins>
......
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<runOrder>random</runOrder>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<id>default-integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
......
</plugins>
</build>
若需要eclipse 的可显环境下可以看到覆盖情况,可以在eclipse安装个插件:EclEmma
参考:https://www.ibm.com/developerworks/cn/java/j-lo-jacoco/
SVN源码管理
源码版本管理利器:SVN
参考我在CSDN博客写的安装配置(CentOS):http://blog.csdn.net/esinzhong/article/details/8013816
Windows的安装配置简单点:https://www.visualsvn.com/server/
不过我更倾向于Linux的,别问我为什么,呵呵……
jenkins yum安装
持续集成的利器:jenkins,官网: http://jenkins-ci.org/
jenkins为何物?可以看看这介绍:http://velep.com/archives/867.html
安装参考: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key sudo yum install jenkins
安装完成后,配置文件在:/etc/sysconfig/jenkins
启动
service jenkins start
如何使用参考:http://blog.csdn.net/littlechang/article/details/8642149
Sonar yum 安装
源码质量分析管理利器:Sonar ,官网:http://www.sonarqube.org/
参考:http://sonar-pkg.sourceforge.net/
sudo wget -O /etc/yum.repos.d/sonar.repo http://downloads.sourceforge.net/project/sonar-pkg/rpm/sonar.repo yum install sonar
安装默认路径在:/opt/sonar/
配置文件在:/opt/sonar/conf/sonar.properties
(本人用的是mysql, mysql的安装也不多说了 ,因此修改:sonar.properties )
sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar9?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
启动
service sonar start
Sonar服务是启动了,访问http://192.168.0.240:9000,还需要maven编译配置的支持,在~/.m2/下创建setting.xml内容如下:
<settings> <pluginGroups> <pluginGroup>org.sonarsource.scanner.maven</pluginGroup> </pluginGroups> <profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- Optional URL to server. Default value is http://localhost:9000 --> <sonar.host.url>http://192.168.0.240:9000</sonar.host.url> <!-- sonar mysql database : change to your mysql info -->
<sonar.jdbc.url>jdbc:mysql://192.168.0.240:3306/sonar9</sonar.jdbc.url> <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver> <sonar.jdbc.username>sonar</sonar.jdbc.username> <sonar.jdbc.password>sonar</sonar.jdbc.password> </properties> </profile> </profiles> </settings>
maven 编译时如下
mvn clean install sonar:sonar
此时便会进行源代质理分析了并提交报告到sonar服务上去了。可以访问http://192.168.0.240:9000看报表了。
Nexus 私有Maven仓库
Nexus用来管理开发的底层核心公用库、代理被GFW墙了的一些公开库(比如googlecode的)非常有效。
安装参考:http://blog.csdn.net/shenshen123jun/article/details/9084293
项目的pom.xml配置如下:
在project节点下加入distributionManagement(用于编译打包上传到maven私有仓库),下面地址为参考,勿直直接使用:)
<distributionManagement> <repository> <id>releases</id> <url>http://192.168.0.240:8060/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>snapshots</id> <url>http://192.168.0.240:8060/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement>
maven 打包上传命令:
mvn deploy
上一步其实还是会打包上传不成功,因为没有设置私有仓库的身份授权,私有仓库身份配置参考:http://blog.csdn.net/hualom/article/details/8070320
私有身份的账号密码需要配置到开发机器的~/.m2/settings.xml的文件settings节点下(~在linux/unix下表地当前用户的根目录,windows是C:\users\{当前用户名}):如下
<servers> <server> <id>snapshots</id> <username>sing</username> <password>password</password> </server> <server> <id>releases</id> <username>sing</username> <password>password</password> </server> </servers>
留意上面的颜色对应,再执行mvn deploy应该就没问题了
还在不间断更新中...