Search code examples
clojureintellij-plugincursive

requre deps in idea clojure repl, get FileNotFoundException


I created a new Leiningen project in idea, and imported some deps in project.clj as follows: deps

and deps seems to be imported: external libraries

But when I try to run repl, and required some deps that I imported in project.clj before, an FileNotFoundException has occurred: FileNotFoundException

Starting nREPL server...
"E:\Program Files\Java\jdk-11.0.8\bin\java.exe" -Dfile.encoding=GBK -XX:-OmitStackTraceInFastThrow -Dclojure.compile.path=E:\idea_projects\clojure_test_second\target\classes -Dclojure_test_second.version=0.1.0-SNAPSHOT -Dclojure.debug=false "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2021.1.3\lib\idea_rt.jar=50688:D:\Program Files\JetBrains\IntelliJ IDEA 2021.1.3\bin" -classpath E:\idea_projects\clojure_test_second\test;E:\idea_projects\clojure_test_second\src;E:\idea_projects\clojure_test_second\dev-resources;E:\idea_projects\clojure_test_second\resources;E:\idea_projects\clojure_test_second\target\classes;C:\Users\asus\.m2\repository\org\clojure\clojure\1.10.1\clojure-1.10.1.jar;C:\Users\asus\.m2\repository\org\clojure\spec.alpha\0.2.176\spec.alpha-0.2.176.jar;C:\Users\asus\.m2\repository\org\clojure\core.specs.alpha\0.2.44\core.specs.alpha-0.2.44.jar;C:\Users\asus\.m2\repository\hiccup\hiccup\1.0.5\hiccup-1.0.5.jar;C:\Users\asus\.m2\repository\clojure\jdbc\clojure.jdbc\0.4.0\clojure.jdbc-0.4.0.jar;C:\Users\asus\.m2\repository\com\h2database\h2\1.4.193\h2-1.4.193.jar;C:\Users\asus\.m2\repository\nrepl\nrepl\0.6.0\nrepl-0.6.0.jar;C:\Users\asus\.m2\repository\clojure-complete\clojure-complete\0.2.5\clojure-complete-0.2.5.jar clojure.main -i C:\Users\asus\AppData\Local\Temp\form-init14732922726375964945.clj
Connecting to local nREPL server...
Clojure 1.10.1
nREPL server started on port 50817 on host 127.0.0.1 - nrepl://127.0.0.1:50817
(require '[clojure.java.jdbc :as jdbc])
Execution error (FileNotFoundException) at clojure-test-second.core/eval1555 (form-init14732922726375964945.clj:1).
Could not locate clojure/java/jdbc__init.class, clojure/java/jdbc.clj or clojure/java/jdbc.cljc on classpath.

jdk version is 11, idea version is 2021.1.3.

I searched solution for a long time, but didn't solve it. And I am a noob in clojure.

Thanks.


Solution

  • You have to

    • add [org.clojure/java.jdbc "0.7.12"] in project.clj file of your leiningen project folder. under :dependencies [ <add into this list> [org.clojure/java.jdbc "0.7.12"]].
    • Then you do $ lein deps from inside folder of your leiningen project folder, to ensure installation of that dependencies.
    • Then if you did M-x cider-jack-in from inside emacs opened inside project folder, you can do your require command. OR you just do $ lein repl from there and you can then do your (require '[clojure.java.jdbc :as j]) - voila!

    Coming from Common Lisp, I was also quite lost like you. Clojure requires Leiningen or Boot to function reasonably.

    Whenever you have to install Clojure in a new machine, install first Leiningen, because you can install Cloure also using Leiningen.

    With Boot, you can even create standalone scripts/executives which uses Clojure. But also with Leiningen see here.

    Install and use Boot

    I think the way you want to use the repl - more freely - suits more to Boot:

    # install boot e.g. by (for linux)
    $ sudo bash -c "cd /usr/local/bin && curl -fsSLo boot https://github.com/boot-clj/boot-bin/releases/download/latest/boot.sh && chmod 755 boot"
    # upgrade!
    $ boot -u
    
    # create your project folders and move into toplevel
    mkdir -p my-project/src
    cd my-project
    
    # then open repl
    $ boot repl
    
    ;; within the repl:
    ;; declare resource-paths and dependencies
    (set-env! :resource-paths #{"src"}
              :dependencies '[[org.clojure/java.jdbc "0.7.12"]])
    
    ;; create a minimal project declaration
    (task-options!
      pom {:project 'my-project
           :version "0.1.0"}
      jar {:manifest {"Foo" "bar"}})
    
    ;; build the minimal project (to install the dependencies!)
    (deftask build
      "Build my project."
      []
      (comp (pom) (jar) (install)))
    ;; call build
    (build)
    
    ;; now, in the repl, you can do:
    (require '[org.clojure/java.jdbc :as j])
    

    Boot is more dynamic - since you can from the repl introduce dependencies and build.