aspose file tools*
The moose likes Java in General and the fly likes cannot load property file from WAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "cannot load property file from WAR " Watch "cannot load property file from WAR " New topic
Author

cannot load property file from WAR

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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

Joined: Apr 14, 2004
Posts: 10336

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:


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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

Joined: Mar 10, 2008
Posts: 326

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

Joined: Jun 28, 2008
Posts: 580
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Jun 28, 2008
Posts: 580
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot load property file from WAR
 
Similar Threads
best place to put configuration properties.
need help reading a properties file
Loading properties file
Urgent: cannot find property file in war when packaged in ear
How to change the key=value pair of properties file dynamically