Created
February 6, 2015 15:08
-
-
Save mikedamage/2b335f76ddda0765ffa1 to your computer and use it in GitHub Desktop.
Java class auto-compiler
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 | |
# | |
# Inotify Java Watcher | |
# by Mike Green <[email protected]> | |
# | |
# Automatically compiles Java classes when their files are saved. | |
# | |
# = Installation: Save this script into the root folder of your Java projects, then run: | |
# $ cd whatever-your-folder-is-called && chmod +x java-watcher.sh | |
# | |
# = Usage: | |
# $ ./java-watcher.sh | |
# | |
# Note: this script requires the "inotify-tools" package. Install it by running: | |
# $ sudo apt-get install inotify-tools | |
cyan="\e[0;36m" | |
green="\e[01;32m" | |
color_reset="\e[0m" | |
if ! which inotifywait >> /dev/null; then | |
echo "Cannot find inotifywait!" | |
exit 1 | |
fi | |
if ! which javac >> /dev/null; then | |
echo "Cannot find javac!" | |
exit 1 | |
fi | |
inotifywait -mr --timefmt '%m/%d/%Y %H:%M:%S' --format '%T %w %f' -e close_write $PWD | while read date time dir file; do | |
if [[ $file == *.java ]]; then | |
echo -e "[${date} ${time}] - ${cyan}Compiling ${file}:${color_reset}" | |
javac "$PWD/$file" | |
finish_date=$(date "+%m/%d/%Y %H:%M:%S") | |
echo -e "[${finish_date}] - ${green}Done!${color_reset}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment