Importing clojure functions from jars
I'm playing around with Clojure, and I can't figure out how to import a function from clojure-contrib.jar. Working from th开发者_StackOverflow中文版is answer, I'm doing the following:
Running the REPL like so:
java -cp clojure.jar:clojure-contrib.jar clojure.main
Then trying to import a function:
user=> (use '[clojure-contrib.duck-streams :only (writer reader)])
It doesn't work, and I get the following error:
java.io.FileNotFoundException: Could not locate clojure_contrib/duck_streams__init.class or clojure_contrib/duck_streams.clj on classpath: (NO_SOURCE_FILE:0)
Trying it with a dot instead of a dash also doesn't work:
user=> (use '[clojure.contrib.duck-streams :only (writer reader)])
I get mostly the same error:
java.io.FileNotFoundException: Could not locate clojure/contrib/duck_streams__init.class or clojure/contrib/duck_streams.clj on classpath: (NO_SOURCE_FILE:0)
What am I doing wrong?
Is clojure.jar
and clojure-contrib.jar
in your current working directory? If not, you need to specify the full path to the JAR files in the CLASSPATH.
This should work
(use 'clojure.contrib)
I don't have clojure handy right now to check, but
(use 'clojure.contrib :only (writer reader))
should also work
It's clojure.contrib, not clojute-contrib. Note dot versus dash.
精彩评论