aspose file tools*
The moose likes JSF and the fly likes Putting a resources file outside the application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Putting a resources file outside the application" Watch "Putting a resources file outside the application" New topic
Author

Putting a resources file outside the application

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 151
Hello,

I am sure this question has cropped up before, and although I have looked around for a suitable answer, I have not found anything that helps.

In my JSF 2.0 application I have a couple of resources files. One is used to specify the paths and file names to files that are read from folders that outside the application, and one is used to initialize a number of variables. At the moment both resources files are in the same folder as the Java classes, as is usually the case.

For example I have code such as:

Which is all well and good, and works without any problems.

However, I need to deploy the war file on another server, and I want to make it easy to edit the properties files and not have them inside the war file. Is there an easy way of putting the properties files in an extenal directory, so that they can be edited, and at the same time my application can know where they are located?

I am using the Glassfish server, but want to avoid, if possible, changing the server, and somehow make the application aware of where the properties files are.

Some advice would be most appreciated - many thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15662
    
  15

The whole resource bundle subsystem is basically interface-based, so you can select from a number of resource providers, including ones that you design yourself.

However, the easiest way to include resources from an externally-located file is to define the resource filename path as a web application resource and use JNDI to look it up. Once you have the filename path, you can use the regular bundle load-from-file mechanism.

For Tomcat, you would do this by adding a resource definition to the webapp's WEB-INF/web.xml file to define its nature and default value. Tomcat can then override the default in the webapp's Context element. Glassfish would use the web.xml part but employ a GlassFish-specific mechanism to set the override. I haven't worked with GlassFish recently enough to know specifically what that is (check with the appropriate Ranch forum if you need Glassfish help).

In the webapp, as part of the core initialization code, you'd do a JNDI lookup to get the value of the resource path. You'd get a JNDI context and use it as the control point to lookup something like "java:comp/env/myresources", where "myresources" is the name you defined in web.xml.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Putting a resources file outside the application
 
Similar Threads
Properties file in EJB Ear
confused between jar and war files
where to put the properties file in WebLogic10 server web & Hibernate application
IBM Exam 157 - Questions and Answers (Sample Exam)
Modify build xml to replace words in an xml or properties file based on a text file