Skip to content
Latchkey

Leiningen "Could not find or load main class clojure.main" in CI

The JVM started but clojure.main was not on the classpath it was given. That means the Clojure jar was not resolved onto the classpath, or the classpath the launcher built is empty or corrupted.

What this error means

A lein or java invocation fails with "Error: Could not find or load main class clojure.main" and the process exits before running any Clojure code.

JVM
Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main

Common causes

Clojure is not on the resolved classpath

The dependency on org.clojure/clojure failed to resolve, or a hand-built java command omitted the Clojure jar.

A corrupted dependency cache

A partially downloaded Clojure jar in ~/.m2 leaves the class unloadable until the cache is refreshed.

How to fix it

Ensure Clojure is a dependency and re-resolve

  1. Confirm [org.clojure/clojure "..."] is in :dependencies (or :deps).
  2. Clear a possibly corrupt cache entry and re-fetch.
  3. Re-run the task so the classpath includes the Clojure jar.
Terminal
rm -rf ~/.m2/repository/org/clojure/clojure
lein deps
lein run

Build the java classpath from the tool

When invoking java directly, get the classpath from Leiningen or the CLI rather than hand-listing jars.

Terminal
java -cp "$(lein classpath)" clojure.main -m myapp.core

How to prevent it

  • Keep org.clojure/clojure in your dependency list.
  • Let the tool build the classpath instead of assembling it by hand.
  • Refresh a corrupted ~/.m2 entry rather than reusing it.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →