3 # A launcher script for Clojure programs. These environment variables can be
4 # used to configure the script:
7 # The root directory where Clojure is installed.
9 # The name of the java executable used to run Clojure.
11 # Additional options to be passed to the java executable.
13 # A path to be added to Clojure's classpath.
14 # CLOJURE_LIBRARY_PATH
15 # A path to be searched for native code such as DLL's or JNI
16 # libraries. This gets added to the Java options as
17 # "-Djava.library.path=$CLOJURE_LIBRARY_PATH".
19 # This directory, and any jars inside it, will be automatically
20 # added to Clojure's classpath.
23 # This should be the path to Jline jar.
25 # make CLOJURE_LIB a path instead of a single directory
26 # allow for adding to CLOJURE_LIB from the command line
29 usage: clojure [options] [file1 [file2] ...]
32 --help, -h show this message
33 --java-cmd, -J the Java executable to use
34 --java-opts, -j add options to be passed on to the JVM
35 --classpath, -cp add to Clojure's classpath
36 --library-path, -L add to the path to search for native libraries
37 --verbose, -v print initialization information
39 ## read ~/.clojurerc for home configuration
40 [ -e ~
/.clojurerc
] && . ~
/.clojurerc
42 ## read ./.clojurerc for project specific configuration
43 [ -e .
/.clojurerc
] && . .
/.clojurerc
45 if [ ! "$CLOJURE_HOME" ]; then
46 # Find the real path to Clojure's home directory if $0 is a symlink
48 while [ -h "$program" ]; do
49 ls=`ls -ld "$program"`
50 link
=`expr "$ls" : '.*-> \(.*\)$'`
51 if expr "$link" : '.*/.*' >/dev
/null
; then
54 program
="`dirname $program`/$link"
57 script_dir
=`dirname "$program"`
58 relative_clojure_home
=`dirname "$script_dir"`
59 CLOJURE_HOME
=`cd "$relative_clojure_home" && pwd`
62 if [ ! "$CLOJURE_JAVA" ]; then
66 if [ ! "$CLOJURE_JAVA_OPTS" ]; then
67 CLOJURE_JAVA_OPTS
="-Dpid=$$"; # set the pid for SLIME
70 if [ ! "$CLOJURE_CLASSPATH" ]; then
74 ## Add Clojure home jars.
75 for jar
in "$CLOJURE_HOME"/*.jar
; do
76 CLOJURE_CLASSPATH
="$CLOJURE_CLASSPATH:$jar"
79 if [ -d "$CLOJURE_LIB" ]; then
80 CLOJURE_CLASSPATH
="$CLOJURE_CLASSPATH:$CLOJURE_LIB"
81 for jar
in "$CLOJURE_LIB"/*.jar
; do
82 CLOJURE_CLASSPATH
="$CLOJURE_CLASSPATH:$jar"
86 # this is now the same for both the repl and for scripts
94 echo "$usage"; exit 1;;
96 CLOJURE_JAVA
="$2"; shift; shift;;
98 CLOJURE_JAVA_OPTS
="$CLOJURE_JAVA_OPTS $2"; shift; shift;;
100 CLOJURE_CLASSPATH
="$CLOJURE_CLASSPATH:$2"; shift; shift;;
102 if [ "$CLOJURE_LIBRARY_PATH" ]; then
103 CLOJURE_LIBRARY_PATH
="$CLOJURE_LIBRARY_PATH:$2";
105 CLOJURE_LIBRARY_PATH
="$2";
114 [ $verbose -eq 1 ] && echo "$CLOJURE_CLASSPATH"
116 # If we didn't get any files to load on the commandline, we want to run the
117 # repl, with command line editing if available.
118 [ $# -eq 0 ] && repl
=1
120 # If the classpath contains the JLine jar, use the JLine console runner
121 if expr "$CLOJURE_CLASSPATH" : ".*jline.*\.jar" >/dev
/null
; then
122 [ $repl -eq 1 ] && jline
="jline.ConsoleRunner"
125 # Enable rlwrap if present
126 if [ $repl -eq 1 ] && [ -z $jline ]; then
127 rlwrap
=`type -p rlwrap`
130 ## Add CLOJURE_LIBRARY_PATH to the Java options if necessary
131 if [ -n "$CLOJURE_LIBRARY_PATH" ]; then
132 CLOJURE_JAVA_OPTS
="$CLOJURE_JAVA_OPTS -Djava.library.path=$CLOJURE_LIBRARY_PATH"
135 cmd
=`echo $rlwrap "$CLOJURE_JAVA" "$CLOJURE_JAVA_OPTS" -cp "$CLOJURE_CLASSPATH" $jline $main "$@"`
136 [ $verbose -eq 1 ] && echo "$cmd"