简体   繁体   中英

Why am I unable to load files in Clojure?

I have just started learning clojure, but have a hard time understanding why my file structure is erroneous. In the main file(main.clj), I have just this:

(ns example.core
    (:gen-class)
    (:load "declare"))

...some code...

and in 'declare.clj', which is in the exact same classpath "project/src", I have this:

(in-ns 'example.core)
...some code...'

From what I understand I should be hitting the right syntax, but I only receive

Could not locate clojurepractice2/src/clojurepractice2/declarations__init.class or clojurepractice2/src/clojurepractice2/declarations.clj on classpath.

from REPL. I am using lein to code, which I know is supposed to automatically set the classpath. Is there something I am missing?
I have tried using load-file With the same results.

The main.clj should have namespace example.main . Or rename it to core.clj . This is definitely an issue with file name and namespace mismatch.

Because the file name should be same as the namespace name. If your file is in src/example/main.clj then the namespace should be example.main . The usage is

(ns example.main
    (:gen-class)
    (:load "declare"))

Is the file path as src/example/main.clj ? Is the main inside the example folder in src ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM