Search code examples
clojurejvm-languages

Is Clojure installable this way?


I downloaded Clojure 1.2 https://github.com/downloads/clojure/clojure/clojure-1.2.0.zip , extracted it under /Library directory, created CLOJURE_HOME, added $CLOJURE_HOME/script to my $PATH.

When I'm trying to run clj or repl scripts that are located under script directory, I'm getting this error:

Exception in thread "main" java.lang.NoClassDefFoundError: jline/ ConsoleRunner Caused by: java.lang.ClassNotFoundException: jline.ConsoleRunner at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

Ok, jline.jar isn't in the CLASSPATH so I checked clj and repl scripts:

CLASSPATH=src/clj:test:test-classes:classes/:script/jline-0.9.94.jar:../clojure-contrib/target/clojure-contrib-1.2.0-SNAPSHOT.jar

if [ -z "$1" ]; then 
   exec java -server jline.ConsoleRunner clojure.main 
else 
   SCRIPT=$(dirname $1) 
   export CLASSPATH=$SCRIPT/*:$SCRIPT:$CLASSPATH 
   exec java -Xmx3G -server clojure.main "$1" "$@" 
fi

I downloaded jline.jar under $CLOJURE_HOME/script but I'm still getting the same error.

This lead me to the question:
What is the role of https://github.com/downloads/clojure/clojure/clojure-1.2.0.zip anyway?
Is it supposed to be used to install Clojure? or just to to build and get clojure.jar?
I noticed no one is talking about installing Clojure this way.
Am I missing something?


Solution

  • Clojure, being a JVM language, has to deal with the JVM classpath. This makes 'installing' it a bit unwieldy and confusing. Rather than install it yourself like this, try out some tools like cljr and cake. I wrote a blog post about this that might be helpful: http://blog.raynes.me/?p=48

    In summary: Check out cljr, cake, and leiningen.

    The majority of people in the Clojure community don't have Clojure 'installed'. Most people use a build tool and/or cljr. It doesn't make a lot of sense to install Clojure to a central place when, inevitably, you're going to need dependency management, and jars will be copied around everywhere anyway. In any case, it's much easier to let a tool handle the classpath for you.