• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Properties file outside the WAR file

 
zabin shariff
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there.

My requirement is to implement internationalization with the properties file outside the WAR. I referred so many websites and forums for this, but could not find a solution. All the forums say about ClassLoader and getResourceAsStream("full url"). I am not able to do this (getting null pointer exception). Moreover I am wondering, even if it works how can I use this in my jsp. Does anybody have any idea so as to how can I access a properties file which is located outside the WAR and still can call a syntax like in my jsf page.

Please help
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Funny you should ask.

http://www.coderanch.com/t/514589/Tomcat/Best-practices-storing-configuration-property

For I18N you should pair the techniques discussed in that thread with the message bundle capabilities of Java. There are specific options in the faces-config.xml file to help with that, and a little searching should turn up some good examples of best practices using message bundles and JSF.
 
Damian Cardozo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I know this is a little late, but this is how I did it (using Tomcat 6).

I 'conf' folder (inside tomcat installation dir) there is a file 'catalina.properties'. this file has a property called "shared.loader". set this property with the path of the folder where you put your i18n files. this path may not contain spaces. Also use "/" instead of "\". for example:

shared.loader=C:/Progra~1/myapp/i18n

then in each xhtml page (or even better, in your template) put this:

<f:view locale="#{localeBean.locale}">
<f:loadBundle basename="filename" var="text" />
<h:head>
......

where "filename" is the name of your i18n files, so you'll have for example "filename_en.properties", "filename_es.properties", "filename_fr.properties" etc..
localeBean is a session scoped managed bean that has a property with the current locale.

you could place the bundle configuration in faces-config, but the problem with this approach is that then you won't be able to clear the cached files, so if you update the language files (change a translation) you won't see the changes in you app.
using f:loadBundle, after a simple call to ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader()); your i18n files will be reloaded, reflecting any changes you've made.

Regards,
Damian



 
Janaka Nawagamuwa
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree to Damian's reply....
For more info, go to following link...
http://theswarmintelligence.blogspot.com/2012/08/use-resource-bundle-messages-files-out.html

This is working for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic