Skip to content

Instantly share code, notes, and snippets.

@admackin
Created March 21, 2012 01:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save admackin/2143295 to your computer and use it in GitHub Desktop.
Save admackin/2143295 to your computer and use it in GitHub Desktop.
Set Java CLASSPATH for a set of library Jars using BASH
#!/bin/sh
# use this for any package (such as ClearParser) which requires setting the
# classpath to a particular set of jar files
if [ -z $BASH_SOURCE ] ; then
echo "Script must be sourced (using '.' or 'source') and run under bash >= 3.0"
exit 1
fi
script_path="${BASH_SOURCE%/*}"
script_path_abs="$(cd $script_path ; pwd)"
jar_path="$script_path_abs/lib"
for jarfile in "$jar_path"/*.jar ; do
if [ -z "$CLASSPATH" ] ; then
CLASSPATH="$jarfile"
else
CLASSPATH="$jarfile:$CLASSPATH"
fi
done
echo "ClearParser base: $script_path_abs; CLASSPATH is now $CLASSPATH"
export CLASSPATH
@admackin
Copy link
Author

If this bash script is saved alongside the 'lib' directory containing the jar files, it should just work, no matter where you source it from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment