Last active
February 7, 2017 16:13
-
-
Save willeccles/deb0b4b06c2dffff0a511ea66757dc89 to your computer and use it in GitHub Desktop.
Compile and run a java program in one command.
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/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