The JavaFileChangeWatcher is a small programm (Jar File: ~10Kb) which watches a single file for changes and executes a command if the file was created or changed.
The program aims to be similar to inotifywatch but platform independent so that it works on Windows as well.
- ...uses the Watcher-API introduced in Java 7 which should make it get along with low system resources.
- ...after a file change was detected waits another second before executing. If another change is detected during that second start to wait another second to reduce command executions if many alterations happen to a file in a small time.
java -jar filewatch.jar [-v] <fileToWatch> <commandToExecute>
Remember that "commandToExecute" is not executed in a shell, so you cannot do any fancy stuff like string expansion (*). I suggest creating a script file (.bat on Windows, .sh on Linux) with your fancy things and just let this program call that script.
The following alternatives I encountered:
- Using the PowerShell on Windows (I could not get that one to work, but I never worked with the MS Powershell before so it's probably just me)
- Belvedere (Is Windows only and I wanted something that works on Linux as well for testing. Additionally it is not lightweight)
- when_changed (Similar to this one, but written in C#. Maybe it works with Mono on Linux, I did not test)
If you know another tool which you think may be helpful for others to find, feel free to create a pull request.
Feel free to create a pull request if you think something important is missing. Please submit tests with your code and remember that this tool is meant to be lightweight, so no huge add ons.