1

I use properties files and the ResourceBundle class in my web application for internationalization (as outlined here: https://docs.oracle.com/javase/tutorial/i18n/resbundle/concept.html).

I now have a properties file for dynamic content (such as user comments) which I would like to update (ie: write to) while the web app is deployed.

This topic has been discussed already, mainly: Where to place and how to read configuration resource files in servlet based application? (My specific case is addressed in the last paragraph).

Can someone elaborate on how and why I would put the properties file outside of the web application. Also,

1) What ramifications would this have for accessing the file through the ResourceBundle.getBundle() method (if the properties file is outside of the web app then accessing it with "packagename.filename" will no longer work).

2) I would like to write to the properties file but I'm not sure how to locate it (so that it will work when I deploy my application on a web server). Right now, I just locate the properties file in the project's "build" folder. But I understand that when I deploy, all of the project's files will be in tomcat under the "document root". Is there a way to locate the file so that it will work when deployed too? (right now the properties files exist both in the build folder and in the src folder).

Community
  • 1
  • 1
theyuv
  • 1,556
  • 4
  • 26
  • 55
  • 1
    Why would you store user comments in a properties file? Dynamic content belongs in dynamic storage, e.g., probably not a file. – Dave Newton Nov 13 '15 at 14:45
  • This is going to be a mess for a number of reasons. Tomcat caches resource-fetches done using `ClassLoader.getResource` (etc) and so does `ResourceBundle`. I agree with @DaveNewton : this is the wrong approach. – Christopher Schultz Nov 13 '15 at 21:59
  • Thank you for your responses. The reason I chose to use a properties file is simply for consistency: Since all my other internationalization is done with properties files/resourceBundle I do it here as well (I would like user comments to be provided in the site's various languages). Do you have any suggestions for an alternative? Just simply placing in my DB would require explicitly testing for locale (the ResourceBundle class is convenient in that it doesn't require this explicit test). – theyuv Nov 14 '15 at 08:38

0 Answers0