【问题标题】:FileNotFoundException with Leiningen and Ring带有 Leiningen 和 Ring 的 FileNotFoundException
【发布时间】:2017-06-14 14:39:00
【问题描述】:

我目前正在通过命令行在我正在制作的名为 reagent_test 的项目中使用 Leiningen 和 Ring,但遇到了一个问题:

C:/...reagent_test>lein ring server
... huge chunk of errors
Caused by: java.io.FileNotFoundException: Could not locate reagent_test/core__init.class or reagent_test/core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
... more errors

如果有人想要这个问题的要点,如果需要,我会做一个。

问题是,文件都在正确的位置。这是我的project.clj

(defproject reagent-test "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"}
  :plugins [[lein-cljsbuild "1.1.5"]
            [lein-ring "0.10.0"]]
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.456"]
                 [ring "1.4.0"]
                 [leiningen "2.7.1"]
                 [reagent "0.6.0"]
                 [garden "1.3.2"]]
  :cljsbuild {:builds {:app {:source-paths ["src/cljs"]}
                            :compiler {:output-to "resources/public/main.js"
                                        :pretty-print true}}}
  :ring {:handler reagent-test.core/-main})

而我的项目结构是这样的(至少,对于相关文件来说):

src:
  clj:
    reagent_test:
      core.clj
  cljs:
    reagent_test:
      core.cljs
project.clj

core.cljcore.cljs 中,我都有这个作为我的命名空间:

(ns reagent-test.core)

注意:文件夹有冒号,文件没有。

【问题讨论】:

    标签: clojure leiningen ring


    【解决方案1】:

    在文件顶部的命名空间声明中,您应该使用破折号:

    (ns reagent-test.core)
    

    而文件(以及文件上方的所有目录)应使用下划线。所以文件名应该是whatever/reagent_test/core.cljwhatever/reagent_test/core.cljs

    【讨论】:

    • 这就是我在core.cljcore.cljs 中所做的——抱歉,我应该把它包括在内。我应该使用namespace sn-p 编辑帖子吗?另外,请参阅文件结构 - reagent_test 位使用下划线而不是破折号。
    • 你的依赖括号没有对齐的另一件事:[[org.clojure/clojure "1.8.0"]] - 似乎最后的括号来得太早了。
    • 啊,不错的收获!谢谢!这是 Visual Studio Code 糟糕的结果,将在问题中解决。
    • 好像没有clj的源路径,只有cljs一个
    • 什么意思?
    【解决方案2】:

    正如克里斯墨菲在他的答案中指出的那样。由于您已经稍微更改了项目目录结构,因此您需要修改您的 project.clj 文件:

    (defproject reagent-test "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"}
      :plugins [[lein-cljsbuild "1.1.5"]
                [lein-ring "0.10.0"]]
      :source-paths ["src/clj"]
      :dependencies [[org.clojure/clojure "1.8.0"]
                     [org.clojure/clojurescript "1.9.456"]
                     [ring "1.4.0"]
                     [leiningen "2.7.1"]
                     [reagent "0.6.0"]
                     [garden "1.3.2"]]
      :cljsbuild {:builds {:app {:source-paths ["src/cljs"]}
                                :compiler {:output-to "resources/public/main.js"
                                            :pretty-print true}}}
      :ring {:handler reagent-test.core/-main})
    

    添加的是 :source-paths 键,它应该指定 Clojure 代码的目录。默认情况下,lein 使用 src 目录作为 Clojure 源文件的根目录。

    【讨论】:

      猜你喜欢
      • 2014-02-06
      • 2015-03-15
      • 2013-06-23
      • 2021-12-14
      • 2014-08-20
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多