Created
March 21, 2012 01:07
-
-
Save admackin/2143295 to your computer and use it in GitHub Desktop.
Set Java CLASSPATH for a set of library Jars using BASH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.