aspose file tools*
The moose likes JSF and the fly likes Properties file outside the WAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Properties file outside the WAR file" Watch "Properties file outside the WAR file" New topic
Author

Properties file outside the WAR file

zabin shariff
Greenhorn

Joined: Jun 03, 2010
Posts: 19
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

Joined: Jun 25, 2001
Posts: 16232
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Damian Cardozo
Greenhorn

Joined: Aug 04, 2011
Posts: 10
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

Joined: Aug 20, 2012
Posts: 1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Properties file outside the WAR file