Java Agent

JaCoCo uses class file instrumentation to record execution coverage data. Class files are instrumented on-the-fly using a so called Java agent. This mechanism allows in-memory pre-processing of all class files during class loading independent of the application framework. The JaCoCo agent collects execution information and dumps it to a local file when the JVM exits.

If you use the JaCoCo Ant tasks you don't have to care about the agent and its options directly. This is transparently handled by the Ant tasks.

The agent jacocoagent.jar is part of the JaCoCo distribution and includes all required dependencies. A Java agent can be activated with the following JVM option:

  -javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]

The JaCoCo agent accepts the following options:

Option Description Default
file Path to the output file for execution data. jacoco.exec
merge If set to true and the execution data file already exists, coverage data is merged to the existing file. If set to false, an existing execution data file will be replaced. true
includes A list of class names that should be included in execution analysis. The list entries are separated by a vertical bar (|) and may use wildcard characters (* and ?). Except for performance optimization or technical corner cases this option is normally not required. * (all classes)
excludes A list of class names that should be excluded from execution analysis. The list entries are separated by a vertical bar (|) and may use wildcard characters (* and ?). Except for performance optimization or technical corner cases this option is normally not required. empty (no excluded classes)
exclclassloader A list of class loader names that should be excluded from execution analysis. The list entries are separated by a vertical bar (|) and may use wildcard characters (* and ?). This option might be required in case of special frameworks that conflict with JaCoCo code instrumentation, in particular class loaders that do not have access to the Java runtime classes. sun.reflect.DelegatingClassLoader