jacoco监听配置:
1、修改tomcat启动文件:
/Users/XXX/Documents/XXX/apache-tomcat-7.0.94/bin/catalina.sh
#why TODO #JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS" JAVA_OPTS="$JAVA_OPTS -javaagent:/Users/XXX/Documents/XXX/soft/jacoco-0.8.4/lib/jacocoagent.jar=includes=*,output=tcpserver,port=17297,address=127.0.0.1,append=true -Xverify:none" #why TODO
2、重启服务
查看jacoco监听已经存在
jacoco生成报告配置:
1、用ant构建项目
配置build.xml文件
<?xml version="1.0" ?> <project name="coverage" xmlns:jacoco="antlib:org.jacoco.ant" default="jacoco"> <!--Jacoco的安装路径--> <property name="jacocoantPath" value="/Users/XXX/Documents/XXX/soft/jacoco-0.8.4/lib/jacocoant.jar"/> <!--最终生成.exec文件的路径,Jacoco就是根据这个文件生成最终的报告的--> <property name="jacocoexecPath" value="/Users/XXX/Documents/XXX/apache-tomcat-7.0.94/webapps/target/jacoco.exec"/> <!--生成覆盖率报告的路径--> <property name="reportfolderPath" value="/Users/XXX/Documents/XXX/soft/jacoco-0.8.4/report/"/> <!--远程tomcat服务的ip地址--> <property name="server_ip" value="127.0.0.1"/> <!--jacoco的端口--> <property name="server_port" value="17297"/> <!--源代码路径可以包含多个源代码--> <property name="webSrcpath" value="/Users/XXX/Documents/code/项目名字/service/src/main/java/" /> <!--<property name="businessSrcpath" value="/home/work/zj/adp-feed-access-business-delivery/src/main/java/"/> <property name="commonSrcpath" value="/home/work/zj/adp-feed-access-business-common/src/main/java/"/> <property name="uasSrcpath" value="/home/work/zj/uas-pbrpc4j/src/main/java/"/>--> <!--.class文件路径可以包含多个--> <property name="webClasspath" value="/Users/XXX/Documents/code/项目名字/service/target/ROOT/WEB-INF/classes/"/> <!--<property name="businessClasspath" value="/home/work/local/adp_launch_feed_1/ROOT/WEB-INF/lib/adp-feed-access-business-delivery/"/> <property name="commonClasspath" value="/home/work/local/adp_launch_feed_1/ROOT/WEB-INF/lib/adp-feed-access-business-common/"/> <property name="uasClasspath" value="/home/work/local/adp_launch_feed_1/ROOT/WEB-INF/lib/uas-pbrpc4j/"/> --> <!--让ant知道去哪儿找Jacoco--> <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"> <classpath path="${jacocoantPath}" /> </taskdef> <!--dump任务: 根据前面配置的ip地址,和端口号, 访问目标tomcat服务,并生成.exec文件。--> <target name="dump"> <jacoco:dump address="${server_ip}" reset="false" destfile="${jacocoexecPath}" port="${server_port}" append="true"/> </target> <!--jacoco任务: 根据前面配置的源代码路径和.class文件路径, 根据dump后,生成的.exec文件,生成最终的html覆盖率报告。--> <target name="report"> <delete dir="${reportfolderPath}" /> <mkdir dir="${reportfolderPath}" /> <jacoco:report> <executiondata> <file file="${jacocoexecPath}" /> </executiondata> <structure name="JaCoCo Report"> <group name="evaluate-platform"> <classfiles> <fileset dir="${webClasspath}" /> </classfiles> <sourcefiles encoding="utf-8"> <fileset dir="${webSrcpath}" /> </sourcefiles> </group> </structure> <html destdir="${reportfolderPath}" encoding="utf-8" /> </jacoco:report> </target> </project>
2、执行antdump和antreport