• Post Reply Bookmark Topic Watch Topic
  • New Topic

Editable properties file in Web Application  RSS feed

 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a situation where in my web application where I need to give the user a configurable properties file which would be kept in the application's folder. Eg:
MyApp
|-->Web Contents
|-->Java Source
|-->properties
      |-->Config.properties

The user would be able to edit the file on wish. Since the file is editable I cannot place it in the classpath as it would require the whole EAR to be re-created and re-deployed. Hence I thought of keeping as per the above model or somewhere else. Now obviously I need the file's absolute path. I cannot do "application.getRealPath()" or something as it is not fail safe.

Is there any method by which we can set a variable, with the file's absolute path, in the app server and then read it in the application? If this is possible, it'll allow the user to pla ce the file anywhere he wishes to.

I have gone through other threads on the web and the ranch, but could not find a satisfactory solution to this problem. Please let me know in case I overlooked.

Thank You

Regards
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would a context parameter in the deployment descriptor do?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "user", do you mean someone who uses the web app, or someone who deploys it and so has access to the server? If the former, the person wouldn't have access to the server file system.

Also, since you mention doing this without redeployment, you need some way to tell the web app that the file has changed and should be reloaded (or have the web app monitor the file's modification date and reload it if that changes).
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:By "user", do you mean someone who uses the web app, or someone who deploys it and so has access to the server? If the former, the person wouldn't have access to the server file system.

Also, since you mention doing this without redeployment, you need some way to tell the web app that the file has changed and should be reloaded (or have the web app monitor the file's modification date and reload it if that changes).


For my case, both the types you defined for "user" would be the same person. Everytime the application runs, it chks if the file has been modified. If yes, it is reloaded.

Bear Bibeault wrote:Would a context parameter in the deployment descriptor do?

Yes that would do I guess. But I am unaware of accessing such a parameter in the code.

Also please tell me if am running full speed into NO ENTRY! If there is another way to handle such a scenario.

Regards
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
We had used external properties file. The advantage was that we could change it and just bounced the JVM without rebuilding the EAR. We placed this file in a shared folder. For local testing, you can add it to the VM Arguments of your app. server
Access this property by using


And as Ulf suggested
Also, since you mention doing this without redeployment, you need some way to tell the web app that the file has changed and should be reloaded (or have the web app monitor the file's modification date and reload it if that changes).
, do something like this if you don't want to redeploy.

Jhakda
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

If we set this up in the deployment descriptor, won't it require the recreation and redeployment of EAR? just wondering

I think for the time being I'll go with the VM args. Still would like to know if there is another way.

Regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!