In my case, I set the value of java.ext.dirs to a list of just one
directory. That directory contains (relative) symbolic links to all
the Jar files and directories I want Clojure to use as its Classpath.
As a concrete example, here's what I have in that directory:
clojure-contrib.classes -> ../../clojure-contrib/classes
clojure-contrib.src -> ../../clojure-contrib/src
clojure.jar -> ../../clojure/clojure.jar
derby.jar -> ../javadb/lib/derby.jar
etc -> ../../../clj/etc
itext-2.0.6.jar -> ../jfreechart/lib/itext-2.0.6.jar
jcommon-1.0.12.jar -> ../jfreechart/lib/jcommon-1.0.12.jar
jfreechart-1.0.9.jar -> ../jfreechart/lib/jfreechart-1.0.9.jar
jsr166y.jar -> ../jsr166y/jsr166y.jar
local -> ../../../clj/local
miglayout-3.6-sources.jar -> ../miglayout/miglayout-3.6-sources.jar
miglayout-3.6-swing.jar -> ../miglayout/miglayout-3.6-swing.jar
I've enclosed the bash script I'm currently using the launch Clojure.
The one required environment variable is CLOJURE_DIRS which I set to
the directory containing the links above. I like how simple the script
is and how easy it is to manage which jars and directories are
available to Clojure REPLs using this method.
--Steve
(note: using this with clojure.contrib.repl-ln requires revision 337
(of today) or later)
#!/bin/bash
# clj: Launches a Clojure REPL with command line arguments
#
# Environment variables:
#
# Required:
#
# CLOJURE_DIRS A list of paths to directories containing (either
directly
# or via symbolic links) the jar files and directories
that
# Clojure will use as its Classpath. The paths are
separated
# by File.pathSeparatorChar (: on UNIX).
#
# Optional:
#
# CLOJURE_MAIN The Java class to launch
# default: clojure.main
# example: clojure.contrib.repl_ln
#
# CLOJURE_OPTS Java options for this REPL's JVM instance
# default:
# example:"-Xms32M -Xmx128M -server"
#
# CLOJURE_INIT Path to an init file to run, an @ prefix specifies a
# classpath-relative path.
# default:
# example:"@init.clj"
set -o errexit
set -o nounset
#set -o xtrace
JAVA=java
OPTS=${CLOJURE_OPTS:-}
DIRS="-Djava.ext.dirs=${CLOJURE_DIRS}"
MAIN=${CLOJURE_MAIN:-clojure.main}
INIT=${CLOJURE_INIT:+--init ${CLOJURE_INIT}}
REPL=--repl
exec $JAVA $OPTS $DIRS $MAIN $INIT $REPL $@
> The "java.ext.dirs" System property provides a very convenient way to
> set up and maintain a Classpath for Clojure REPLs.
[...]
> In my case, I set the value of java.ext.dirs to a list of just one
> directory. That directory contains (relative) symbolic links to all
> the Jar files and directories I want Clojure to use as its Classpath.
>
> As a concrete example, here's what I have in that directory:
java.ext.dirs has a default value that -Djava.ext.dirs overwrites, so
make sure you replace whatever your platform's Java expects (like
$JAVA_HOME/lib/ext). I've been bitten before trying to speak HTTPS
while not having sunpkcs11.jar available.
-Drew
> java.ext.dirs has a default value that -Djava.ext.dirs overwrites, so
> make sure you replace whatever your platform's Java expects (like
> $JAVA_HOME/lib/ext). I've been bitten before trying to speak HTTPS
> while not having sunpkcs11.jar available.
Thanks for the info, Drew, R, and Laurent.
I've come up with this alternative for Mac OS X and Linux that gives
the same convenient management, but doesn't use java.ext.dirs.
--Steve
#!/bin/bash
# clj: Launches a Clojure REPL with command line arguments
#
# Environment variables:
#
# Required:
#
# CLOJURE_EXT The path to a directory containing symlinks to the jar
# files and directories that Clojure will use as its
# Classpath.
#
# Optional:
#
# CLOJURE_MAIN The Java class to launch
# default: clojure.main
# example: clojure.contrib.repl_ln
#
# CLOJURE_OPTS Java options for this REPL's JVM instance
# default:
# example:"-Xms32M -Xmx128M -server"
#
# CLOJURE_INIT Path to an init file to run, an @ prefix specifies a
# classpath-relative path.
# default:
# example:"@init.clj"
set -o errexit
set -o nounset
#set -o xtrace
EXT="$(find ${CLOJURE_EXT} -type l -print0 | tr "\0" ":")"
export CLASSPATH="${EXT}${CLASSPATH:-}"
JAVA=java
OPTS=${CLOJURE_OPTS:-}
MAIN=${CLOJURE_MAIN:-clojure.main}
INIT=${CLOJURE_INIT:+--init ${CLOJURE_INIT}}
REPL=--repl
exec $JAVA $OPTS $MAIN $INIT $REPL $@