0

I see a lot of how to read the file or locate it, but I've been trying to run Properties.store() and it simple does not modify the file.

I can read, get and set properties but store doesn't work. Should it work or is not meant to work?

If it doesn't work, how can I modify the file, so when the server restart those properties do not get lost?

javaNoober
  • 1,338
  • 2
  • 17
  • 43
  • use whatever IDE you're using to rebuild the project and then export back to a .war (if using eclipse. In the case of netbeans a 'clean and build' will cause it to update/export to the .war file) then republish to your container (aka server). – Dark Star1 Dec 06 '11 at 23:51
  • If you really want to do this then do not package your properties file inside the WAR or use an exploded deployment. – Steven Dec 06 '11 at 23:55

3 Answers3

4

No; it's inside a WAR.

Technically you could un-zip it, modify it, zip it back up. But don't.

Properties like that should be stored in a DB, in JNDI, or in a file outside of the war.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • ok, precise answer, and something my boss would clearly understand, thanks – javaNoober Dec 07 '11 at 01:36
  • @javaNoober Don't overestimate bosses ;) – Dave Newton Dec 07 '11 at 01:38
  • could you point me on how the JNDI alternative should be implemented? – javaNoober Dec 07 '11 at 01:38
  • and I wasn't underestimating my boss, but he was saying "if you can read the file you should be able to modify it" – javaNoober Dec 07 '11 at 01:39
  • @javaNoober No no, don't *overestimate* his/her ability to understand. Anything. Ever. Here's an [SO question](http://stackoverflow.com/questions/965061/how-can-i-store-jee-configuration-parameters-outside-of-an-ear-or-war) with a reference that may also provide additional ideas. – Dave Newton Dec 07 '11 at 01:42
0

Property files bundled inside a JAR are not meant to change because they make part of the distribution.

Slash
  • 496
  • 2
  • 8
0

I wouldn't mess with unzipping/rezipping a WAR file, just as a piece of advice. I have done that in the past and it did not work so well.

Johnny Rocket
  • 1,394
  • 3
  • 17
  • 25