• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Putting a resources file outside the application

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic