Ajay
Ajay

Reputation: 7428

Property file load

I have a web application that reads content from a property file. When will this property file be loaded into memory. ie. Once I deploy the application with some content in the prop file, and after deployment , I change the contents of the prop file, will the changes be reflected or do I have to redeploy?

EDIT : An accessor class' static block reads content from the property file, which is a part of a deployed web application. Now after deployment, i change the property file contents. Will the accessor class read the changes or will it take up the old values?

EDIT2 : when the class is reloaded, will it surely take up the new modified file or rather take up the file cached during deployment(if at all it is cached)

Upvotes: 2

Views: 2828

Answers (4)

aslamK
aslamK

Reputation: 81

Apache Commons Configuration provides automatic reloading/saving of file-based configurations.

Upvotes: 0

Ken Liu
Ken Liu

Reputation: 22914

Assuming that the property file is being loaded by the Properties class, then the property file will be loaded once when the Properties#load() method is called. It will not automatically be reloaded unless your application specifically supports reloading or if your web container restarts the web application during hot deployment.

update: Since the property file is loaded in a static initializer, then the property file will be reloaded when the class is reloaded (e.g. when the web app is hot deployed). If you want to debug this, a simple println() in the static initializer will show you when this happens.

Upvotes: 2

user162883
user162883

Reputation:

If this file is loaded by your class than I am pretty sure it won't reload it by it self.

If I were you I would have a separate thread that in given time intervals wakes up, checks whether the file modification date has changed and if it did than reloads it.

Upvotes: 0

Nate
Nate

Reputation: 16898

It depends on the app server - generally, you'd have to redeploy. But some app servers, in certain configurations may monitor files and kick off a redeploy when they detect file changes. (as an example - I believe Tomcat will automatically redeploy when it detects file changes in exploded deployments.)

Upvotes: 1

Related Questions