clojure.tools/namespace刷新失败,使用"没有命名空间:foo"

时间:2017-05-29 16:28:05

标签: clojure namespaces

我使用tools.namespace在REPL上提供名称空间的智能重新加载。但是,在调用refreshrefresh-all时,会引发错误。

user=> (require '[clojure.tools.namespace.repl :as tn])
user=> (tn/refresh)
:reloading (ep31.common ep31.routes ep31.config ep31.application user ep31.common-test ep31.example-test)
:error-while-loading user

java.lang.Exception: No namespace: ep31.config, compiling:(user.clj:1:1)

它似乎最终处于这种奇怪的状态,(require ep31.config)在没有错误的情况下工作,但之后命名空间并没有实际定义。

2 个答案:

答案 0 :(得分:6)

我有点想到这一点,这似乎是情况的组合

  • target/classes之前的lein uberjar还有AOT编译的类,而不是之前的target/classes
  • tools.namespace在加载的命名空间是AOT编译时无法正常工作
  • 默认情况下,
  • jar位于类路径

很长一段时间,如果您之前进行过uberjar / target/版本修改,请删除target/classes,事情应该重新开始。

我还无法解决的问题是为什么{{1}}在类路径上开始。我怀疑Leiningen正在添加它,但还没有找到它发生的地点或原因。

答案 1 :(得分:-1)

我很难学到这一点,:target-path的文档说(https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L309-L313):

;; All generated files will be placed in :target-path. In order to avoid
;; cross-profile contamination (for instance, uberjar classes interfering
;; with development), it's recommended to include %s in in your custom
;; :target-path, which will splice in names of the currently active profiles.
:target-path "target/%s/"

我想必须存在:target-path "target/%s/"不是默认值的遗留原因。