3

I'm playing around with Clojure, and I can't figure out how to import a function from clojure-contrib.jar. Working from this 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?

Community
  • 1
  • 1
Steve Armstrong
  • 5,252
  • 7
  • 32
  • 43

3 Answers3

2

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.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • When I tested this exact example, yes they were in my working directory. Specifying their full path doesn't change the error I get though. – Steve Armstrong Jul 22 '10 at 18:43
  • Adding the full path "/usr/lib/clojure-contrib-1.1.0/clojure-contrib.jar" to my CLASSPATH did it for me. It is the sole thing on my CLASSPATH; not that that should matter. I thought jar files would get picked up automatically, I guess I was wrong: http://en.wikipedia.org/wiki/Classpath_%28Java%29#Setting_the_path_of_a_Jar_file. – caseyboardman Jul 23 '10 at 01:18
1

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

Marko
  • 30,263
  • 18
  • 74
  • 108
  • I get the following error: java.io.FileNotFoundException: Could not locate clojure/contrib__init.class or clojure/contrib.clj on classpath: (NO_SOURCE_FILE:0) – Steve Armstrong Jul 23 '10 at 00:32
  • I redownloaded clojure-contrib.jar, and it works now. I had a corrupt or unusable jar. – Steve Armstrong Jul 23 '10 at 01:00
  • This answer is plain wrong. There is no clojure.contrib namespace, so `(use 'clojure.contrib)` cannot possibly do anything useful. – kotarak Jul 23 '10 at 07:37
0

It's clojure.contrib, not clojute-contrib. Note dot versus dash.

kotarak
  • 17,099
  • 2
  • 49
  • 39