views:

112

answers:

3
admin@apollo:~/clojure$ clojure
Clojure 1.0.0-
user=> (require 'clojure.contrib.str-utils)
java.io.FileNotFoundException: Could not locate clojure/contrib/str_utils__init.class or clojure/contrib/str_utils.clj on classpath:  (NO_SOURCE_FILE:0)
user=> 

What have I done wrong while installing clojure? Why cant clojure locate my java classes? I have java installed.

admin@apollo:~/clojure$ sudo apt-get install sun-java6-jre sun-java6-jdk
sudo: unable to resolve host apollo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
sun-java6-jre is already the newest version.
sun-java6-jdk is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.


admin@apollo:~/clojure$ java -version
    java version "1.6.0_20"
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
    admin@apollo:~/clojure$ 

please help! thanks!

+1  A: 

str utils is something that comes with clojure-contrib. It's not a standard java lib. So, simply installing java wont help. When you start clojure make sure the clojure-contrib jar is mentioned in the classpath. You can get the latest(1.2) clojure and clojure-contrib jar from clojure.org

For e.g. This is how i start the REPL

java -server -cp ~/clojure-1.2.0.jar:~clojure-contrib-1.2.0.jar:. clojure.main --repl
letronje
thanks for the help, can u be more specific? I tried running that line and I got: http://pastebin.com/wjBrgDwM
vick
that command is specific to my machine. General way to invoke repl would be : java -cp {path-to-clojure-jar}:{path-to-clojure-contrib-jar}:. clojure.main --repl
letronje
@vick: You need to replace the `~/clojure-1.2.0.jar` and `~clojure-contrib-1.2.0.jar` (<- typo -- should read `~/clojure-contrib...`) bits with paths to the actual copies of the relevant jars on your system. From the question text, I gather that you have a copy of `clojure.jar` in `~/clojure`, so you'd use `~/clojure/clojure.jar`; if you put the contrib jar in the same directory, the path to it will look similar.
Michał Marczyk
By the way, you can skip the final `:.` if you don't actually want to include the current directory on the classpath.
Michał Marczyk
I did: updatedb; locate clojure-contrib-1.2.0.jar; and it does not even find the file! how do I install those two jar files?
vick
@vick: please get the jars from here ~> http://clojure.org/downloads
letronje
+4  A: 

It's great to learn figure this out manually because understanding the classpath makes the world a better place. In practice Many Clojurians use leiningen, maven, or cake.

Personally i would reccomend using leiningen:

There are lots of reasons not to use an automated tool and these things dont fit everyone. For the time it takes to set this up its worth it to me even for simple one-liners.

Arthur Ulfeldt
there is alsow the cljr project check it out.
nickik
Is it not also necessary to run "lein self-install" after downloading the lein script?
dreish
i though so, when I checked the leiningen page on gihub that step is not in the getting started instructions. dont think it would hurt to run lein self-install
Arthur Ulfeldt
A: 

I use maven to handle all dependencies, and it works a treat.

I wrote a blogpost here: http://learnclojure.blogspot.com/2010/08/clojure-emacs-swank-slime-maven-maven.html about how to set up a working clojure/slime setup from scratch on a new machine. It takes about a minute.

Anyway, if all you want is a running repl, then you can:

Install maven

Get the pom.xml from the blogpost, and put it in a directory.

In that directory run $ mvn clojure:repl

Maven will download everything you need and start a repl, which should be jline-enabled so it's actually usable.

I know this works on Ubuntu, it should work fine on all other linuxes and mac osx. Does anyone know if it works on Windows too?

But if you can use emacs, the combination of clojure/emacs and slime is unbeatable. Do let me know if you have any problems.

John Lawrence Aspden