SpringOne 2GX 2011

Chicago, October 25-28, 2011

Setting up Clojure 1.1.0 on Mac OSX

Posted by: Ken Sipe on 2010-02-21 22:27:00.0
As part of the Lambda Lounge, established by Alex Miller (Thanks!!), we have started a group to study the SICP. We just started and are going virtual... if you would like to participate, email or tweet me (@kensipe). In the process of studying SICP and LISP, I plan on focusing on Clojure. Clojure was previously on my machine as I was reading Stu's book Programming Clojure, however increased usage would require some maturing of my tools. This led to the discovery of Mark Reid's blog on Setting up Clojure for Mac OS X, however I assume based on updates and changes over the last year, it requires some updates.

Read Mark's blog first... getting clojure, the clojure-contrib and jline. Here are the differences:
  • Create an environment variable CLOJURE_HOME assigned to the directory for clojure
  • Create the /bin directory for the clj script included below
  • Add $CLOJURE_HOME/bin in the $PATH
  • Clojure is distributed with clojure.jar in the CLOJURE_HOME... so I maintain that. It is expected that contrib and jline are in the same directory.
  • Mark's clj script has been updated below... The previous script invokes classes which are depreciated.
Here is the updated script:

#!/bin/bash
# Runs Clojure using the classpath specified in the `.clojure` file of the
# current directory.
#
# Ken Sipe 2010-02-20
# Inspired by Mark Reid
# original: http://github.com/mreid/clojure-framework/blob/e1c80cc650f448713243be8272dba1fa3c1a7cea/clj
#
# This scripts expects $JAVA_HOME and $CLOJURE_HOME to be defined for the system it is running on
# The clojure.jar is standardly in the clojure_home dir (and not in the lib directory), so
# the expectation is that clojure-contrib.jar and the jline.jar are placed in the same dir

CLJ_DIR=$CLOJURE_HOME
CLOJURE=$CLJ_DIR/clojure.jar
CONTRIB=$CLJ_DIR/clojure-contrib.jar
JLINE=$CLJ_DIR/jline-0_9_5.jar
CP=$PWD:$CLOJURE:$JLINE:$CONTRIB

# Add extra jars as specified by `.clojure` file
if [ -f .clojure ]
then
CP=$CP:`cat .clojure`
fi

if [ -z "$1" ]; then
java -server -cp $CP \
jline.ConsoleRunner clojure.lang.Repl
else
java -server -cp $CP clojure.main -i $*
fi
Love the TextMate support and the history support in JLine!

About Ken Sipe

Ken Sipe

Ken has been a practitioner and instructor of RUP since the late 1990s, and an extreme programmer and coach since the middle 2000s. Ken has worked with Fortune 500 companies to small startups in the roles of developer, designer, application architect and enterprise architect. Ken's current focus is on enterprise system automation and continuous delivery systems.

Ken is an international speaker on the subject of software engineering speaking at conferences such as JavaOne, JavaZone, Jax-India, and The Strange Loop. He is a regular speaker with NFJS where he is best known for his architecture and security hacking talks. In 2009, Ken was honored by being awarded the JavaOne Rockstar Award at JavaOne in SF, California and the JavaZone Rockstar Award at JavaZone in Oslo, Norway as the top ranked speaker.

More About Ken »

NFJS, the Magazine

2011-09-01 00:00:00.0 Issue Now Available
  • Build Your Own Technology Radar

    by Neal Ford
  • Programming with Scala Traits, Part Two

    by Venkat Subramaniam
  • MVC Meet Javascript, Javascript Meet MVC

    by Brian Sam-Bodden
  • The Art of Groovy Command Expressions in DSLs

    by Hamlet D`Arcy
Learn More »