命名空间未加载到 clojure 基座中

namespace not loaded in clojure pedestal

我正在使用基座指南中的初学者指南,但是当尝试使用命名空间(需要“测试”)时,我收到以下错误消息: “user/eval2012 (REPL:1) 处的执行错误 (FileNotFoundException)。 无法在类路径上找到 test__init.class、test.clj 或 test.cljc。”

尝试时会发生同样的事情 (require 'hello)

我正在使用 lein repl。

我有一个名为 test 的目录,在 src 下有一个名为 test.clj

的文件

test/src/test.clj:

(ns test
(:require [io.pedestal.http :as http]
[io.pedesteal.http.route :as route]))

test/src/hello.clj:

(defn respond-hello [request]
{:status 200 :body “Herllo world”})

有什么想法吗?

test/deps.edn:

:deps                                                
 {io.pedestal/pedestal.service {:mvn/version "0.5.7"}
  io.pedestal/pedestal.route   {:mvn/version "0.5.7"}
  io.pedestal/pedestal.jetty   {:mvn/version "0.5.7"}
  org.slf4j/slf4j-simple       {:mvn/version "1.7.28"}}
 :paths ["src"]}

clj repl 不同于 lein repl。要使用 lein repl,您需要一个 project.clj 文件。

我使用建议的 clj 成功完成了 Pedestal's beginner guide,但是在使用 lein repl 时我遇到了你的错误:

user=> (require 'test)
Execution error (FileNotFoundException) at user/eval2006 (REPL:1).

user=> (require 'hello)
Execution error (FileNotFoundException) at user/eval2008 (REPL:1).
Could not locate hello__init.class, hello.clj or hello.cljc on classpath.

我查看了 clj 项目和 Leiningen 项目之间的区别,这是我看到的:

  • clj 使用 deps.edn。 Leiningen 将依赖项放在 project.clj
  • clj 有 :paths ["src"]。莱宁根在 project.clj
  • 中有 :main:target-path

所以为了从 clj 切换到 lein repl我添加了 project.clj 文件:

(defproject pedestal "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.10.1"]
                 [io.pedestal/pedestal.service "0.5.7"]
                 [io.pedestal/pedestal.route "0.5.7"]
                 [io.pedestal/pedestal.jetty "0.5.7"]]
  :main ^:skip-aot test
  :target-path "target/%s")

遵循我的目录结构...

.../pedestal/src/test.clj
.../pedestal/project.clj
.../...

当我再次开始时,我什至不需要 (require 'test) 甚至 (test/start)(start) 成功了,页面将加载

Leiningen 不同于准系统 clj 工具。 它以不同的方式指向启动文件 (?),并以不同于指南推荐的准系统 clj 项目 的方式引入依赖项。

从你的问题来看,我没有看到 project.clj,所以也许这就是你需要的。