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.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.
Terminal
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.
Terminal
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.
Related guides
Clojure "ClassNotFoundException" / "NoClassDefFoundError" in CIFix Clojure "java.lang.ClassNotFoundException" and "NoClassDefFoundError" in CI - a Java class the code uses…
Leiningen "lein: command not found" on the runner in CIFix "lein: command not found" in CI - Leiningen is not installed on the runner or not on PATH, so no lein tas…
Leiningen "No :main namespace specified" in CIFix Leiningen "No :main namespace specified" in CI - lein run or uberjar has no entry point because :main is…