How to connect a JaCoCo agent to an application server

I use JBoss and run Jenkins Selenium tests. I want to measure the coverage of code from Selenium tests, so apparently I should bind the JaCoCo java agent to the server. I did like this:

./run.sh -c Default -Djavaagent:[path to Jenkins workspace]/tools/libs/jacocoagent.jar=destfile=[path to Jenkins]/jacoco.exec 

However, no output file is generated. I point to jacocoagent.jar in the Jenkins path here, but is it that jacocoagent.jar and jacoco.exec should be in the real path to the server, not Jenkins?

+4
source share
1 answer

javaagent should be passed as a VM option, for example:

 -javaagent:[path to Jenkins workspace]/tools/libs/jacocoagent.jar=destfile=[path to Jenkins]/jacoco.exec 

You pass it as a system property (using -D).

You can pass VM parameters to the Jboss application server through the JAVA_OPTS environment variable. (run.sh will select it if JAVA_OPTS is exported before running the run.sh script). Something like this should do:

 export JAVA_OPTS="$JAVA_OPTS -javaagent:[path to Jenkins workspace]/tools/libs/jacocoagent.jar=destfile=[path to Jenkins]/jacoco.exec" ./run.sh 

More details on javaagent configuration can be found here:

http://www.eclemma.org/jacoco/trunk/doc/agent.html

+4
source

All Articles