Getting an exception when trying to run lein

2019-06-28 03:52发布

问题:

I get the following exception when trying to run lein in linux.

Exception in thread "main" java.lang.NoClassDefFoundError: clojure.core.protocols$fn__5393
   at java.lang.Class.initializeClass(libgcj.so.10)
   at clojure.core.protocols__init.load(Unknown Source:16)
   at clojure.core.protocols__init.<clinit>(Unknown Source)
   at java.lang.Class.initializeClass(libgcj.so.10)
   at java.lang.Class.forName(libgcj.so.10)
   at clojure.lang.RT.loadClassForName(RT.java:1578)
   at clojure.lang.RT.load(RT.java:399)
   at clojure.lang.RT.load(RT.java:381)
   at clojure.core$load$fn__4519.invoke(core.clj:4915)
   at clojure.core$load.doInvoke(core.clj:4914)
   at clojure.lang.RestFn.invoke(RestFn.java:408)
   at clojure.core__init.load(Unknown Source:5342)
   at clojure.core__init.<clinit>(Unknown Source)
   at java.lang.Class.initializeClass(libgcj.so.10)
   at java.lang.Class.forName(libgcj.so.10)
   at clojure.lang.RT.loadClassForName(RT.java:1578)
   at clojure.lang.RT.load(RT.java:399)
   at clojure.lang.RT.load(RT.java:381)
   at clojure.lang.RT.doInit(RT.java:416)
   at clojure.lang.RT.<clinit>(RT.java:302)
   at java.lang.Class.initializeClass(libgcj.so.10)
   at clojure.main.<clinit>(main.java:20)
   at java.lang.Class.initializeClass(libgcj.so.10)
   at java.lang.Class.forName(libgcj.so.10)
   at java.lang.Class.forName(libgcj.so.10)
   at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.VerifyError: verification failed at PC 214 in      
clojure.core.protocols$fn__5393:invoke((Ljava.lang.Object;Ljava.lang.Object;Ljava.lang.Obje    ct;)Ljava.lang.Object;): incompatible type on stack
   at java.lang.Class.initializeClass(libgcj.so.10)
   ...25 more

I've followed the instructions on their github page, but no luck. I thought it would be fun to start learning clojure today but instead I've had nothing but problems, I don't even know what leiningen is, other than I apparently have to have it.

回答1:

sorry about the frusteration,

Leiningen is a build tool to take the pain out of getting hacking on a new clojure project. Before leiningen existed many people would try to "install" clojure by downloading a jar file out build it from source. Instead of doing any of that you just specify the version you want to use in the leiningen project.clj file and it installs it locally as a dependency for that project.

have you run:

  • lein new hello_clojure
  • cd hello_clojure
  • edit project.clj and set it to use clojure 1.3.0 :dependencies [[org.clojure/clojure "1.3.0"]
  • lein deps
  • lein repl
  • (+ 1 2 3 4)

When things go wrong with leiningen I generally:

  • lein upgrade
  • rm lib/*
  • lein deps

Problems like this are uncommon (for me) and usually fairly specific, so perhaps you would do well to drop into #clojure on irc.freenode.net and ask. It's a very friendly croud dont worry.