JaCoCo for Liberty JVM Coverage | Generated by AI

Home 2025.08

You can do it—attach JaCoCo to the Liberty JVM that runs your EAR. The key is: JaCoCo must sit inside the same JVM as Liberty, not in your Python runner.

Here are reliable setups (pick one).


1) Simple & robust: write to file on JVM exit

When to use: you can stop the Liberty server after tests.

  1. Make the agent jar available (one-time in your build)
<!-- copy jacoco agent into target/jacoco/jacocoagent.jar -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>3.6.1</version>
  <executions>
    <execution>
      <id>copy-jacoco-agent</id>
      <phase>prepare-package</phase>
      <goals><goal>copy</goal></goals>
      <configuration>
        <artifactItems>
          <artifactItem>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <version>0.8.12</version>
            <classifier>runtime</classifier>
            <destFileName>jacocoagent.jar</destFileName>
          </artifactItem>
        </artifactItems>
        <outputDirectory>${project.build.directory}/jacoco</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>
  1. Add a Liberty JVM option (file: wlp/usr/servers/<serverName>/jvm.options)
-javaagent:${server.config.dir}/jacoco/jacocoagent.jar=output=file,append=false,includes=com.myco.*,excludes=org.slf4j.*,destfile=${server.output.dir}/jacoco/jacoco-it.exec
  1. Run flow
  1. Generate report
<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.12</version>
  <executions>
    <execution>
      <id>report-it</id>
      <phase>verify</phase>
      <goals><goal>report-aggregate</goal></goals>
      <configuration>
        <dataFile>${env.SERVER_OUTPUT_DIR}/jacoco/jacoco-it.exec</dataFile>
        <includes>
          <include>com/myco/**</include>
        </includes>
      </configuration>
    </execution>
  </executions>
</plugin>

(Or use jacococli:)

java -jar jacococli.jar report /path/to/jacoco-it.exec \
  --classfiles module1/target/classes --classfiles module2/target/classes \
  --sourcefiles module1/src/main/java --sourcefiles module2/src/main/java \
  --html target/jacoco-it-report

2) Live dump without stopping Liberty (TCP server mode)

When to use: you want to keep Liberty running and pull coverage on demand.

  1. jvm.options:
-javaagent:${server.config.dir}/jacoco/jacocoagent.jar=output=tcpserver,address=*,port=6300,append=false,includes=com.myco.*
  1. Run Liberty, execute Python tests, then dump:
# pulls coverage over TCP and writes a .exec locally
java -jar jacococli.jar dump --address 127.0.0.1 --port 6300 --destfile jacoco-it.exec --reset

Now generate the report as above. Tip: --reset clears counters so you can take multiple snapshots during a long run.


3) Containers / CI (env-style)

java -jar jacococli.jar merge node1.exec node2.exec --destfile merged.exec

Notes & gotchas


If you share your EAR’s module layout (EJB/WAR modules and package roots), I can drop in an exact report-aggregate config and a tiny script to: start Liberty → run Python tests → fetch dump → build HTML report in one go.


Back Donate