2012-07-25 129 views
11

所以我有這個工作流程的問題:如何新Clojure庫在REPL加載

我願意就我的Clojure項目REPL打字路程,意識到我需要另一個庫,是不是在我的project.clj,說在這種情況下,我需要tools.cli庫。

我在編輯器中打開project.clj並在條目添加到:dependencies

 [org.clojure/tools.cli "0.2.1"] 

然後,在項目目錄中,我在shell中鍵入lein deps在必要的庫

後拉在技​​術上所有的類文件已經準備好加載,但是如果我回到我的repl並輸入:

> (use 'tools.cli) 

我得到這個:

=>> FileNotFoundException Could not locate tools/cli__init.class 
    or tools/cli.clj on classpath: clojure.lang.RT.load (RT.java:432) 

所以我不得不重新啓動我的REPL,浪費時間的一大堆重新配置REPL的地方,我是我所需要的庫之前的狀態。

有沒有辦法只是在庫中動態加載?例如,我跑lein deps後,我剛回到REPL和類型:

> (load-library "tools.cli") 
> (use 'tools.cli) 

在此先感謝

+2

見http://stackoverflow.com/questions/11327624/load-a-new-dependency-in-slime/ – georgek 2012-07-25 01:48:36

+0

大。那解決了它。 – zcaudate 2012-07-25 04:17:59

回答

7

石榴是你:

https://github.com/cemerick/pomegranate

它支持下載和另外的在運行時新的依賴,比如:

(add-dependencies :coordinates '[[incanter "1.2.3"]] 
        :repositories (merge cemerick.pomegranate.aether/maven-central 
             {"clojars" "http://clojars.org/repo"})) 
0

您可以嘗試在一個庫使用lein-try的repl。

~/.lein/profiles.clj

{:user {:plugins [[lein-try "0.4.3"]]}}

command line

$ lein try clj-time "0.5.1" 
Fetching dependencies... (takes a while the first time) 
lein-try loaded [clj-time "0.5.1"] 

nREPL server started on port 57036 
REPL-y 0.2.0 
Clojure 1.5.1 
    Docs: (doc function-name-here) 
      (find-doc "part-of-name-here") 
    Source: (source function-name-here) 
Javadoc: (javadoc java-object-or-class-here) 
    Exit: Control+D or (exit) or (quit) 

user=>