2011-01-29 68 views
15

試圖在java庫中導入一個沒有結果的類。我在Eclipse Helios上逆時針運行。 commons-land-2.6.jar位於構建路徑中。我是Clojure的新手,無法弄清楚。所有幫助非常感謝!將Java類導入到Clojure中

當然這工作得很好:

1:7 exp2=> (import '(java.io FileReader)) 

> java.io.FileReader

但這並不:

1:6 exp2=> (import '(org.apache.commons.lang.StringUtils)) 

>零

這是最終目標:

1:10 exp2 =>(defn whitespace? [字符])

> java.lang.Exception的(StringUtils的(字符的isEmpty)。):無法解析符號:在這種情況下(REPL-1 StringUtils的:10)

回答

23

你讓一個錯誤 - 你沒有在org.apache.commons.lang和StringUtils類之間放置空間。進口的這種形式可以讓你從一個包導入多個類,例如:

(import '(org.apache.commons.lang StringUtils SystemUtils)) 

如果要導入只有一個類,那麼你可以使用的版本,不帶括號:

(import 'org.apache.commons.lang.StringUtils) 

而且由於在StringUtils的功能是靜態的,你需要使用下面的代碼:

(StringUtils/isEmpty character) 

調用其功能