2017-05-29 47 views
2

我正在使用tools.namespace來爲REPL上的名稱空間提供智能重新加載。但是,當致電refreshrefresh-all時,會引發錯誤。clojure.tools /名稱空間刷新失敗,並顯示「No namespace:foo」

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)作品沒有錯誤,但事後命名空間不能實際上說明這個奇怪的狀態結束。

回答

4

我有點想通了這一點,這似乎是的情況下留在target/classes

  • 有AOT編譯的類從做lein uberjar組合以前
  • tools.namespace不正常加載時命名空間AOT編譯
  • target/classes默認情況下在classpath

那麼長的故事小號hort,如果你之前構建了jar/uberjar,那麼刪除target/並且事情應該重新開始。

我還沒有能夠解決的問題是爲什麼target/classes是在類路徑上開始。我懷疑它正在被Leiningen添加,但還沒有發現它在哪裏或爲什麼發生。

+0

這是正確的。 Leiningen默認將'target/classes'放在類路徑上,原因有兩個:1)爲已編譯的Java源提供應用程序,2)AOT編譯的輸出目錄('* compile-path *')必須爲on類路徑。 –

+1

因此,如果你在做'lein uberjar'之後做了'lein clean',你不會遇到你的問題嗎?或者,只要你進入一個糟糕的狀態,就像你在問題中所描述的那樣,「乾淨」。 –

-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/"不是默認。

+0

儘管這個鏈接可能回答這個問題,但最好在這裏包含答案的基本部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/ review/low-quality-posts/18777954) –

+1

好點!包括':target-path'的文檔,現在答案應該更有意義(文檔在描述問題時非常簡潔)。 – Viesti

相關問題