Thursday, October 8, 2009

Shell Script to build a classpath dynamically with all jars in a directory

copied from http://twit88.com/blog/2008/02/21/unix-shell-script-to-build-classpath-dynamically/ (thanks!)

#!/bin/sh

buildClassPath() {
jar_dir=$1
if [ $# -ne 1 ]; then
echo "Jar directory must be specified."
exit 1
fi
class_path=
c=1
for i in `ls $jar_dir/*.jar`
do
if [ "$c" -eq "1" ]; then
class_path=${i}
c=2
else
class_path=${class_path}:${i}
fi
done
echo $class_path
#return $class_path
}

CP=`buildClassPath /tmp/lib`
echo $CP


A simplified version:

COH_CLASSPATH=.:$SL_CACHE_CONF_DIR:$COHERENCE_HOME/lib/coherence.jar
for i in `ls $SL_CACHE_LIB_DIR/*.jar`
do
COH_CLASSPATH=${COH_CLASSPATH}:${i}
done

No comments: