问题
I am using JBoss and running Selenium tests from Jenkins. I want to measure code coverage from Selenium tests, so apparently I should attach the JaCoCo java agent to the server. I have done 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 ever generated. I am here pointing to jacocoagent.jar in the Jenkins path, but is it so that the jacocoagent.jar and jacoco.exec must be in the actual server path, not Jenkins?
回答1:
The javaagent needs to be passed as a VM option like this :
-javaagent:[path to Jenkins workspace]/tools/libs/jacocoagent.jar=destfile=[path to Jenkins]/jacoco.exec
You are passing it as a system property (using -D).
You can pass VM options to the Jboss application server through a JAVA_OPTS environment variable. (the run.sh will pick it up if the 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 information on the javaagent configuration can be found here :
http://www.eclemma.org/jacoco/trunk/doc/agent.html
来源:https://stackoverflow.com/questions/13952035/how-to-attach-jacoco-agent-to-application-server