Getting code for my application using JavaCalc JavaCalc on Tomcat

I want to measure the coverage of integration test code using JaCoCo and Sonar tools.

To do this, I run Tomcat 5.5, configured by the JaCoCo agent, to get the dump file from JaCoCo.

Thus, I set JAVA_OPTS for this:

 set JAVA_OPTS=-Xrs -XX:MaxPermSize=256m -XX:PermSize=256m -XX:NewRatio=3 -Xms512m -Xmx1024m -XX:+UseParallelGC -javaagent:C:\dev\servers\jacoco-agent.jar=destfile=C:\dev\servers\jacoco.exec,append=true,includes=my.application.* 

When I start Tomcat, the file C:\dev\servers\jacoco.exec , but the data is not populated.

Something I forgot in my server configuration?

Sincerely.

+10
java tomcat sonarqube jacoco
source share
3 answers

As far as I remember, the file will be filled during the disconnection of Tomcat.

+7
source share

I understand that this may not be an option 2 years ago when this question was asked, but at the moment you have other options for getting JaCoCo execution data without disabling Tomcat (or any JVM equipped with the Java Java agent JaCoCo).

First take a look at the current documentation for the JaCoCo Java Agent: http://www.eclemma.org/jacoco/trunk/doc/agent.html

You can use the output = tcpserver parameter for the JaCoCo agent so that the Java agent listens for commands. You can set address = * to listen on tcpserver on all interfaces, and you can set the argument port = 6300 to select the port on which tcpserver should be listened.

Through tcpserver, a JaCoCo java agent can be instructed to send you data whenever you request it.

If your JVM is currently JMX-enabled, you have one more option that you can use without opening additional ports. By setting jmx = true, the JaCoCo java agent provides an MBean with which you can interact.

If you are using maven, you can take a look at the newly created plugin to collect JaCoCo data from a remote JVM at runtime. The project for the plugin is located at:
https://github.com/mattcj/jacocotogo

+10
source share

Besides the maven solution, you can also consider https://www.eclemma.org/jacoco/trunk/doc/cli.html

Basically, you start your service on a remote machine with the javaagent option, for example (you can change the port number and omit include if you want to have coverage for all classes):

-javaagent: /tmp/jacocoagent.jar=port=36320,destfile=jacoco-it.exec,output=tcpserver,includes=abcd*"

Then connect to the remote computer by specifying the address of the remote host, or open the tunnel for the remote computer. The following example assumes that I have configured port forwarding between the local 36320 host and the 36320 remote host

java -jar jacococli.jar dump --port 36320 --destfile/tmp/jacoco-it.exec

If you have multiple .exec files, you need to merge them:

java -jar jacococli.jar merge/tmp/jacoco-it-1.exec/tmp/jacoco-it-2.exec --destfile/tmp/merge

Then generate the html report (path1 may be the path to the jar file or the class files folder)

java -jar jacococli.jar report/tmp/jacoco-it.exec --classfiles path1 --sourcefiles path2 --html/tmp/report

+2
source share

All Articles