• 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

How to read properties files from outside Container?

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Web Container Gurus!

Ive got a servlet from which I want to load properties/config files. Today these files are located in WEB-INF/classes, but I want to relocate them to a location within the same server that is outside this specific web app or Tomcat installation. My thought is to refer to these files using the File object.

Is this possible, if so how do I do it?
Thanks in advance.

Kind regards

[ August 14, 2007: Message edited by: Dominic Steng�rd ]
[ August 14, 2007: Message edited by: Dominic Steng�rd ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would make the path to the properties file a context init param.
 
Dominic Steng�rd
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for your quick reply. :-)

Yes I will make it a context init parameter. But my question is more related to if it is even possible for a File object within serlvetA in webappA to reach fileA, even though fileA is not located within webappA? FileA will be located somewhere else on the filesystem.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can do that. However, just remember your app is no longer a simple war, and it has other dependency files that must also be deployed. Often I put properties in a database table. Often times your properties differ depending on if you are in dev/test/prod. If you go to your db connection to get properties you can easily update them at any time with sql (as opposed to ftp and vi for example), and you don't have to remember to deploy different properties files for dev, test, prod or even to set an indicator that you are in dev/test/prod.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dominic Steng�rd:
Hi Ben,

Thanks for your quick reply. :-)

Yes I will make it a context init parameter. But my question is more related to if it is even possible for a File object within serlvetA in webappA to reach fileA, even though fileA is not located within webappA? FileA will be located somewhere else on the filesystem.



Yes.
You might have issues if the file isn't actually on the same machine as the container (Windows network, NFS, etc..) but if they're on the same machine and you have an absolute path to the file, you shouldn't have a problem.

Other issues could be file permissions, and/or Java security policies, if your container is running under one.
 
Dominic Steng�rd
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help youve provided.
The application is up and running well. :-)
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One method that I like is to put a directory in the classpath. Place the property file in the directory. You can even have a directory structure under that directory to give some sort of context. Then use the Classloader getResourceAsStream to get a stream to the properties file. From there you can load up a Properties instance.

I like this better than having an a priori directory location in a Servlet context, (This is hard to change) or requiring a -D option that contains the path location.


Originally posted by Dominic Steng�rd:
Hi Web Container Gurus!

Ive got a servlet from which I want to load properties/config files. Today these files are located in WEB-INF/classes, but I want to relocate them to a location within the same server that is outside this specific web app or Tomcat installation. My thought is to refer to these files using the File object.

Is this possible, if so how do I do it?
Thanks in advance.

Kind regards

[ August 14, 2007: Message edited by: Dominic Steng�rd ]

[ August 14, 2007: Message edited by: Dominic Steng�rd ]

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic