Skip to content

Instantly share code, notes, and snippets.

@willeccles
Last active February 7, 2017 16:13
Show Gist options
  • Save willeccles/deb0b4b06c2dffff0a511ea66757dc89 to your computer and use it in GitHub Desktop.
Save willeccles/deb0b4b06c2dffff0a511ea66757dc89 to your computer and use it in GitHub Desktop.
Compile and run a java program in one command.
#! /bin/bash
echo Compiling $1...
# make the build directory if it doesn't exist already
mkdir -p "`pwd`/build"
javac "$1" -d "`pwd`/build"
rc=$? # return code of javac
[ $rc -eq 0 ] || exit $rc; # exit if the return code of the compilation isn't 0
filename=$(basename "$1")
name="${filename%.*}"
echo Attempting to run $name...
olddir="`pwd`"
cd "`pwd`/build"
java "$name"
cd "$olddir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment