When using Clover, why do I get a java.lang.NoClassDefFoundError when I run my code?

Q: When using Clover, why do I get a java.lang.NoClassDefFoundError when I run my code? This probably indicates that you do not have Clover's runtime classes in your runtime classpath. See 'Classpath Issues' in Working with Distributed Applications.

Having Clover on the compile classpath is not enough. Classes instrumented by Clover call into Clover's coverage recorder, so these classes must be available while your application or your tests are executed.

You may see the same problem reported as a NoClassDefFoundError on org_openclover_runtime/CoverageRecorder, or as a "Could not initialize class" error naming a class with the $__CLR... suffix, for example:

Could not initialize class com.acme.MyClass$__CLR3_2_02t2thng9gff

Which JAR do I need at runtime?

You can use either of the following:

  • clover-runtime.jar (the org.openclover:clover-runtime artifact) - recommended. It contains Clover's runtime classes only, so it cannot be used for compilation or reporting, but thanks to its reduced size you can bundle it into your own application's JAR. Available since Clover 4.0.6. See Clover Runtime JAR.
  • clover.jar (the org.openclover:clover artifact) - the full JAR. This also works, but it is considerably larger.

See "Could not initialize class" error at runtime and NoClassDefFoundError org_openclover_runtime/CoverageRecorder in the Knowledge Base for more solutions.