Skip to content

Instantly share code, notes, and snippets.

@mikedamage
Created February 6, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedamage/2b335f76ddda0765ffa1 to your computer and use it in GitHub Desktop.
Save mikedamage/2b335f76ddda0765ffa1 to your computer and use it in GitHub Desktop.
Java class auto-compiler
#!/bin/bash
#
# Inotify Java Watcher
# by Mike Green <mike.is.green@gmail.com>
#
# 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