Thanks for your relpy, Mars.I will answer your problem and tell my setup detailly.
1)I use ant ,the ant vresion is Apache Ant(TM) version 1.9.7
2)the jacoco version is
JaCoCo 0.7.8.201606240924
3
a)the web application which I collect covereage data is a jar ,
the jar is got by maven command :mvn clean package,the compiler is maven-compiler-plugin:3.1:compile
we startup the application use command:
nohup java -jar -Xmx1536m -XX:MaxPermSize=512M -javaagent:/opt/jacocoagent.jar=includes=*,output=tcpserver,port=10003,address=1127.0.0.1 -Djava.security.egd=file:/dev/./urandom server-3.2.0-SNAPSHOT.jar --server.port=9001 --shell.ssh.port=2002 --spring.profiles.active=build > nohup.log &
I restart my application after add the javaagent
b)I donot know how to configure the application ,so I unzip the server-3.2.0-SNAPSHOT.jar ,and delete the lib file(if I donot delete the lib file the command ant report will show error message Error while creating report Caused by: java.io.IOException: Error while analyzing lib/bcprov-jdk16-1.46.jar@org/bouncycastle/LICENSE.class.
Caused by: java.lang.IllegalStateException: Can't add different class with same name: org/bouncycastle/LICENSE )
and this is my build.xml
========================================================================================
project xmlns:ns0="antlib:org.jacoco.ant" default="rebuild" name="credit-card-server">
<!--Jacoco的安装路径-->
<property name="jacocoantPath" value="/opt/apache-ant-1.9.7/lib/jacocoant.jar"/>
<property name="jacocoResultPath" value="/jacoco/target"/>
<!--最终生成.exec文件的路径,Jacoco就是根据这个文件生成最终的报告的-->
<property name="jacocoexecPath" value="/jacoco/jacoco.exec"/>
<!--生成覆盖率报告的路径-->
<property name="reportfolderPath" value="${jacocoResultPath}/report/"/>
<!--远程tomcat服务的ip地址-->
<property name="server_ip" value="127.0.0.1"/>
<!--前面配置的远程tomcat服务打开的端口,要跟上面配置的一样-->
<property name="server_port" value="10003"/>
<!--源代码路径可以包含多个源代码-->
<property name="source" value="/jacoco/source/credit-card-server/src/main/java/" />
<!--.class文件路径可以包含多个-->
<!--确认-->
<property name="classes" value="/jacoco/classes/credit-card-server/"/>
<!--让ant知道去哪儿找Jacoco-->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${jacocoantPath}" />
</taskdef>
<target name="clean">
<delete dir="${reportfolderPath}" />
</target>
<!--dump任务:
根据前面配置的ip地址,和端口号,
访问目标tomcat服务,并生成.exec文件。-->
<target name="dump">
<ns0:dump address="${server_ip}" reset="false" destfile="${jacocoexecPath}" port="${server_port}" append="false"/>
</target>
<!--jacoco任务:
根据前面配置的源代码路径和.class文件路径,
根据dump后,生成的.exec文件,生成最终的html覆盖率报告。-->
<target name="report">
<ns0:report>
<executiondata>
<file file="${jacocoexecPath}" />
</executiondata>
<structure name="credit-card-server">
<classfiles>
<fileset dir="${classes}">
</fileset>
</classfiles>
<sourcefiles>
<fileset dir="${source}" />
</sourcefiles>
</structure>
<html destdir="${reportfolderPath}" />
<csv destfile="${reportfolderPath}/report.csv" />
<xml destfile="${reportfolderPath}/report.xml" />
</ns0:report>
</target>
<target depends="clean,report" name="rebuild" />
</project>
==========================================================================
( someone tells I donot need unzip the jar file ,but I donnt know how to configuer it .I have used jacoco with ant before, but it is a war applicatiuon ,I can get the classes easily.)
4) I just unzip the jar file , delete the jar and lib file ,and donot modily the clsses manual.
I can tell you what I do after I see the html report
a)first,I calls an http interface manual, the use ant dump ,I found the .exec file size increased
b) I checked the application ,the source file is same with the branch code(git pull) and the jar applicaion is same with the branch code .
c) I checked the session ,it show the classes I calls , but the detail html page is still like the picture I show you .but somecode of the applicaion seems right(the highted code is continues)
在 2016年7月12日星期二 UTC+8下午11:07:27,Marc R. Hoffmann写道: