I need to implement a configuration file, which should be rescanned periodically or after an edit, what should I do?
I tried
config = new ConfigSlurper().parse(Config);
its not working when Config.groovy changes dynamically.
Example (from comment below)
MyConfig.groovy
class MyConfig {
public static ConfigObject config
public static void run() {
config = new ConfigSlurper().parse(Config)
}
public static void printconfig() {
println config.options.video.enable
}
}
MyConfig.run()
for( int i = 0 ; i < 10 ; i++ ) {
Thread.sleep(3000)
MyConfig.printconfig()
}
Config.groovy
options { video { enable = false } }
You seem to parse the config file once, then never re-parse it…
What you could do is store the last modified date of the file, and call
run()again fromprintConfigif it detects the file has been modified…Also, I assume you have a copy/paste error… Shouldn’t:
be:
Or something?