Wednesday, May 30, 2012

inotifywait - run scripts on file changes

When working on a project in Java, I often need to stop/start maven whenever I make changes to the source code. I wanted to have maven restart automatically whenever I changed the source code. I ended up using some bash scripts to get the job done. inotifywait will run the script whenever a file inside src is saved. This could also be done to automatically run test when source code changes.
while inotifywait -re close_write src; do ./; done
sleep 1
mvn tomcat:run -o &
pkill -kill -f tomcat:run