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.
Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.mainCommon 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
- Confirm
[org.clojure/clojure "..."]is in:dependencies(or:deps). - Clear a possibly corrupt cache entry and re-fetch.
- Re-run the task so the classpath includes the Clojure jar.
rm -rf ~/.m2/repository/org/clojure/clojure
lein deps
lein runBuild the java classpath from the tool
When invoking java directly, get the classpath from Leiningen or the CLI rather than hand-listing jars.
java -cp "$(lein classpath)" clojure.main -m myapp.coreHow to prevent it
- Keep
org.clojure/clojurein your dependency list. - Let the tool build the classpath instead of assembling it by hand.
- Refresh a corrupted
~/.m2entry rather than reusing it.