13

I was trying to understand Clojure spec. While setting up a clojure project I am getting following error while requiring the clojure.spec.alpha:

Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath., compiling:
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$script_opt.invokeStatic(main.clj:335)
at clojure.main$script_opt.invoke(main.clj:330)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.lang.Var.invoke(Var.java:379)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

My project.clj:

(defproject testing "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [org.clojure/spec.alpha "0.1.143"]
                 [org.clojure/core.specs.alpha "0.1.10"]])

and core.clj:

(ns testing.core
  (:require [clojure.spec.alpha :as s]))

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

I will be thankful, if someone can help me out.

user7697691
  • 303
  • 2
  • 9
  • The same project.clj and core.clj are working for me. I notice `com.intellij` in the stack trace; how are you running this? Are you able to run `lein repl` in the project directory from the command line? – Taylor Wood Feb 06 '18 at 13:47
  • Can you please post the output of `lein repl` command? – Pardeep Singh Feb 06 '18 at 14:04
  • `lein repl` runs ok for me too. Could you please describe how exactly did you run it? – Anton Chikin Feb 06 '18 at 15:09
  • Here is when i try to run lein repl: `lein repl nREPL server started on port 61605 on host 127.0.0.1 - nrepl://127.0.0.1:61605 REPL-y 0.3.7, nREPL 0.2.12 Clojure 1.9.0 Java HotSpot(TM) 64-Bit Server VM 1.8.0_151-b12 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e` – user7697691 Feb 06 '18 at 20:43
  • I just tried to run core.clj – user7697691 Feb 06 '18 at 20:50
  • Are you using Cursive or some other Intellij plugin? – Jonah Benton Feb 09 '18 at 03:04
  • Yes, im using Cursive – user7697691 Feb 12 '18 at 10:47
  • Same error with no project, just java -jar clojure-1.9.0.jar (on Windows 10) – Shawn Hoover Feb 12 '18 at 14:08
  • You might try removing `org.clojure/spec.alpha` and `org.clojure/core.specs.alpha` (`spec` ships with Clojure 1.9) and re-booting `Cursive`. – nrako Feb 15 '18 at 18:37

4 Answers4

4

I did a lein clean and it started working

Caleb Macdonald Black
  • 1,494
  • 12
  • 17
3

For those who experience this problem on 1.9, see https://groups.google.com/forum/#!msg/clojure/-ovhQXtzhgw/XBm_rfcICgAJ

With 1.8, you can just run java -jar clojure-1.8.0.jar that you have in your .m2 and RELP will start instantaneously. With 1.9, it's no longer the case. You need additional libraries that you might not have in your .m2 by default.

You will have them though if you install you Clojure based on official guide.

yuranos
  • 8,799
  • 9
  • 56
  • 65
2

I had the same error, I don't know clojure but had to fix some NoClassDefFoundError exceptions testing Kafka Storm using org.apache.storm.kafka.KafkaSpout.

First exception was: NoClassDefFoundError: clojure/lang/IFn

This I fixed by including clojure-1.9.0.jar in the classpath.

Next, this exception:

FileNotFoundException: Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath

later realized they have another jar spec.alpha-0.1.143.jar for this.

Hope this helps someone else!

xgMz
  • 3,334
  • 2
  • 30
  • 23
  • If you add clojure-1.9.0 then will storm not complain about multiple versions of Clojure on class path? – Manoj Arya Aug 16 '19 at 10:12
  • I didn't see that error. Don't expect it based on this: https://stackoverflow.com/questions/34728795/ – xgMz Apr 03 '20 at 18:37
1

What worked for me was adding test.check library as a dependency to my classpath

apiyo
  • 103
  • 7