Skip to content
Latchkey

Clojure "ClassNotFoundException" / "NoClassDefFoundError" in CI

The JVM could not load a Java class the Clojure code references. ClassNotFoundException means the class was never on the classpath; NoClassDefFoundError means it was present at compile time but is missing or failed to initialize at run time.

What this error means

A run fails with "java.lang.ClassNotFoundException: com.example.Widget" or "NoClassDefFoundError", often after a (:import ...) or Java interop call.

JVM
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass
com.example.Widget
Syntax error (ClassNotFoundException) compiling at (myapp/core.clj:5:1).

Common causes

The providing dependency is missing at runtime

The jar that contains the class is not in :dependencies/:deps, or is only in a profile not active for this task.

A version skew between compile and run classpaths

The class existed when compiled but a different runtime version (or an uberjar that excluded it) no longer provides it, giving NoClassDefFoundError.

How to fix it

Add the dependency that provides the class

  1. Find which library packages the missing class.
  2. Add its coordinate to :dependencies (or :deps) in the active profile.
  3. Re-resolve and re-run so the class is on the classpath.
project.clj
:dependencies [[org.clojure/clojure "1.11.1"]
               [com.example/widget-lib "2.0.1"]]

Align compile and runtime versions

Ensure the same dependency version is present at run time as at compile time, and that an uberjar does not exclude the providing jar.

How to prevent it

  • Declare every interop dependency in the profile that runs.
  • Keep compile-time and runtime dependency versions identical.
  • Verify uberjar packaging includes the classes you import.

Frequently asked questions

What causes ""ClassNotFoundException""?
The jar that contains the class is not in :dependencies/:deps, or is only in a profile not active for this task.
How do I fix "ClassNotFoundException"?
Add the dependency that provides the class

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card