Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot load property file from WAR

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am storing property files in in a WAR-FILE in the subdirectory:
/WEB-INF/classes/myProperty.properties.

Now, I want to load this file:



But it does not load the file. So I assume, the path is false.

Any Ideas?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trpically you would load properties files as a resource from the classpath, so you never have to know the path of the file itself. Can you not just try:
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! It works well!

Do you know, how I can (over)write the property-values stored in my file?

config.setProperty("key", "newValue");

does not work.

Have I write the whole file again, with the stored map from the file before or can I overwrite only the specific key with a new value?


 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What we do in our projects is store the default properties in the war or jar-file and then have the modified properties-file written to either the user directory (defined by the user property 'user.dir') or another suitable directory.

If the user directory or properties store contains a properties file, we use that, otherwise we use the default properties file.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats good.

What about EJB which can contain more than one WAR-Files?

One default.properties in EJB and all one custom properties in each WAR-File?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet container has its own temp file space (for each web application). The ServletContext should contain an attribute called javax.servlet.context.tempdir that hold this value.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm..I create a tempfile in my servlet..for what? I can store a properties-file in each-war file and call it within the servlet (or managed-bean).
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic