在Clojure REPL中,當嘗試使用外部庫時,我收到FileNotFoundException
。例如,我使用lein new example-twitter-project
創建了一個新項目。然後我編輯文件:加載my-project.core時出現FileNotFoundException異常
project.clj
:
(defproject example-twitter-project "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]
[clojure-twitter "1.2.6-SNAPSHOT"]])
src/example-twitter-project/core.clj
:
(ns example-twitter-project.core
(:use 'twitter))
然後我跑lein deps
,然後lein repl
。
example-twitter-project$ lein repl
REPL started; server listening on localhost port 23833
user=> (use :reload-all 'example-twitter-project.core)
FileNotFoundException Could not locate quote/twitter__init.class or quote/twitter.clj on classpath: clojure.lang.RT.load (RT.java:430)
在同一時間,我可以use
直接從REPL外部庫:
user=> (use 'twitter)
nil
user=> (doc twitter/with-oauth)
-------------------------
twitter/with-oauth
([consumer access-token access-token-secret & body])
Macro
Set the OAuth access token to be used for all contained Twitter requests.
nil
我應該怎麼做才能夠在項目中使用這個外部庫?
如果我添加-main
函數並嘗試運行該腳本,我會得到類似FileNotFoundException
,所以這不僅是一個REPL問題。
Exception in thread "main" java.lang.RuntimeException: java.io.FileNotFoundException: Could not locate quote/twitter__init.class or quote/twitter.clj on classpath:
at clojure.lang.Util.runtimeException(Util.java:165)
...
Caused by: java.io.FileNotFoundException: Could not locate quote/twitter__init.class or quote/twitter.clj on classpath:
at clojure.lang.RT.load(RT.java:430)
...
請注意,庫的名稱和它的命名空間是不同的。這可能是原因嗎?
P.S. lein version
:Leiningen 1.7.1上的Java 1.6.0_24 OpenJDK的64位服務器VM