When doing lein compile
or lein jar
, I ran into this error. While at the same time lein run
worked fine (at least most of the time...)
#~/foo 11:51:59 > lein jar
Compiling foo.core
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Symbol
at clojure.core$find_ns.invoke(core.clj:3657)
at clojure.core$load_one.invoke(core.clj:5201)
at clojure.core$compile$fn__4615.invoke(core.clj:5397)
at clojure.core$compile.invoke(core.clj:5396)
at user$eval27.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
After several hours of debugging, I cracked it:
#~/foo 11:53:55 > cat project.clj
(defproject foo "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:main "foo.core"
:dependencies [[org.clojure/clojure "1.3.0"]])
Turns out that :main must not be a string (although this works fine in lein run
), but a Symbol
#~/foo 11:53:55 > cat project.clj
(defproject foo "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:main 'foo.core
:dependencies [[org.clojure/clojure "1.3.0"]])
Hope this will help someone save several hours!
Thank you both! I am using :aot and :main. In my case, it was a problem with :main, but I could only get it to work by setting :main to an argument without a single tick. Using the single tick would lead to the error:
I'd be curious how either of you managed to debug into this issue as I don't think I'd ever have gotten past this on my own. lein errors / clojure compilation errors can be baffling and there is no clear way to peel back the layers of the onion and figure out what is causing the error.