2012-01-10 72 views
1

我有以下目錄中的文件male_female.clj在Windows上:無法加載文件

C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src\examples 

啓動REPL之前,我切換到該目錄:

U:\>c: 
C:\>cd C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src\examples 

然後我啓動REPL:

C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src\examples>lein repl 
Warning: classpath not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic classpath or change the name. 
REPL started; server listening on localhost:13278. 

然後我嘗試加載該文件,但得到以下錯誤:

user=> (load-file "male_female.clj") 
user=> FileNotFoundException male_female.clj (The system cannot find the file specified) java.io.FileInputStream.open (:-2) 

我在做什麼錯在這裏?在啓動REPL之前,該文件肯定位於我更改的目錄中。

回答

3

你在使用Programming Clojure repo嗎?我只是克隆它並嘗試了同樣的事情(儘管在Mac上)並且出現了相同的錯誤。

如果是,請嘗試從Git倉庫的根目錄下運行lein repl,然後使用(load "examples/male_female")。然後,您可以通過使用(in-ns 'examples.male-female)切換到名稱空間或完全使用完全限定名稱examples.male-female/m等來訪問此文件中的定義。這適用於我。

我不確定load-file的外觀,但我認爲load將在Java類路徑中查找。您可以使用(System/getProperty "java.class.path")從Clojure REPL中檢查類路徑。

編輯

我用它嘗試閱讀load-filedocs後,發現這個工作太:(load-file "src/examples/male_female.clj"),無論我是在項目中。這可能與Leiningen以及它認爲的項目根源有關。