Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-reload changed files in Java

I have a lot of configuration files that modify how my application behaves. I want to be able to make a change and it gets reflected in the application right away when saving the file. Is there a Java library to help with this?

I could simply keep a list of files with their timestamps and continuously check in a background thread when a timestamp changes. Doesn't seem too difficult, but maybe there's a more efficient way to do this? Custom triggers when certain properties have changed would be nice.

I'm using Spring 3.1, is there a built-in mechanism or solution which works nicely with Spring?

UPDATE: Apparently JDK7 now includes this functionality through its Watch Service API: "Most file system implementations have native support for file change notification. The Watch Service API takes advantage of this support where available. However, when a file system does not support this mechanism, the Watch Service will poll the file system, waiting for events." So this'll be my motivation to migrate to JDK7.

like image 321
at. Avatar asked Oct 14 '11 22:10

at.


1 Answers

Edited:

http://commons.apache.org/configuration/userguide/howto_filebased.html

like image 115
lpinto.eu Avatar answered Oct 16 '22 14:10

lpinto.eu