apache - Save the modified Property file inside WAR deployed on server -


we trying use apache propertiesconfiguration in our project using jsf , jboss.

my property file located inside package demo.prop name of prop1.prop

inside war file same present under /web-inf/classes/demo/prop/prop1.prop

using

facescontext.getcurrentinstance().getexternalcontext().getresource("/web-inf/classes/demo/prop/prop1.prop");

i able fetch property file. when try extract string property file using

propertiesconfiguration pc1=new propertiesconfiguration(a);                 string s1=(string)pc1.getproperty("user_name"); 

i able proper string. using set property method able set property also.

pc1.setproperty("user_name", "hardcodedstring"); 

but not able save file location. no matter not able save file using pc1.save.

can please try tell me how can save file original location changes done in property file remain is.

modifying war file bad idea (for example, web servers may notice file modification redeploy app, there may problems when server explodes war on deployment etc.)

i suggest applying alternative approach - possibilities are:

  1. place properties in database table, can modified
  2. use external properties file overriding "prop1.prop" file settings. can pull off example follows. assume default property values bundled in war , modified values saved other path, defined using system property - let it's called config_location. after loading properties bundle read them external "overrides.prop" file - overrides defaults "prop1.prop":

    propertiesconfiguration pc1=new propertiesconfiguration(a); try(filereader propreader = new filereader(system.getenv().get("config_files") +"/overrides.prop"){ pc1.load(propreader); }

    when need save changes, "overrides.prop" - save properties, not changed ones, should have no negative effects.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -