How to attach JaCoCo Agent to application server

巧了我就是萌 提交于 2019-12-22 07:47:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!