0

We try to use JaCoCo (0.8.12) to collect code coverage information in the Grails (5.3.3) web application compiled for Java11 and running under Tomcat (9.0.88).

Following JaCoCo instructions, I tried to add Java agent to JAVA_OPTS and CATALINA_OPTS in setenv.sh and catalina.sh files. The most information I get was a handful apache classes. No classes from our web application at all.

To enable JaCoCo real-time instrumentation, we used one of the follow command:

export JAVA_OPTS="$JAVA_OPTS -javaagent:/root/jacocoagent.jar=destfile=/root/jacoco.exec,append=true"

or

export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/root/jacocoagent.jar=destfile=/root/jacoco.exec,append=true"

Neither of them produce coverage info about our web application.

What should we do?

2
  • It seems the values of JAVA_OPTS and CATALINA_OPTS are used to start the Tomcat itself, but the Tomcat uses a different class loader to start the webapps, and that class loader doesn't inherit these options. Is it a way to set the Java Agent for the web app itself instead of Tomcat? Commented Nov 4, 2024 at 19:18
  • I will try to do off-line instrumentation, but that would be a less desirable option Commented Nov 4, 2024 at 19:21

1 Answer 1

0

It seems the Tomcat kills the JVM before JaCoCo agent has a chance to download the results. To avoid this and to get the whole report, can use the command line interface:

java -jar <jacococli> dump --port <port> --destfile <dump-file>

Additional optional parameter --reset would empty internal data after dumping the report.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.