Skip to content

Instantly share code, notes, and snippets.

@reinhrst
Created March 8, 2012 10:59
Show Gist options
  • Save reinhrst/2000430 to your computer and use it in GitHub Desktop.
Save reinhrst/2000430 to your computer and use it in GitHub Desktop.
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Symbol

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!

@messiach
Copy link

I ran into this same issue, however I was using :aot in the project.clj file:

(defproject foo "1.0.0-SNAPSHOT"
      :description "FIXME: write description"
      :aot ["foo.core"]
      :dependencies [[org.clojure/clojure "1.3.0"]])

Should be:

(defproject foo "1.0.0-SNAPSHOT"
      :description "FIXME: write description"
      :aot [foo.core]
      :dependencies [[org.clojure/clojure "1.3.0"]])

Note the double quotes removed from the :aot argument...

@joshuabenuck
Copy link

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:

clojure.lang.PersistentList cannot be cast to java.lang.String
(defproject foo "1.0.0-SNAPSHOT"
      :description "FIXME: write description"
      :aot [foo.core]
      :main foo.core
      :dependencies [[org.clojure/clojure "1.3.0"]])

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.

@scottburton11
Copy link

👍 these many years later

@mackenziestarr
Copy link

thank you for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment