• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

How to read a property file from WAR

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have packed a property file in the WAR under the package WEB-INF as
/WEB-INF/Contant.properties
I want to read and extract the contents of this property file in my java class.
My code is as follows:
String filePath = "/WEB-INF/Contant.properties";
Properties prop = new Properties();
prop.load(new FileInputStream(filePath));

Hashtable ptable = (Hashtable)prop;

is this correct ???
thanks in advance
KSK
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,
Please keep your properties file under WEB-INF/classes/ directory of your war file.
( /WEB-INF/classes/Contant.properties ).
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An Answer and a Question...

We too keep the properties file in the WEB-INF/ folder. Is there a best practice that suggests that it should be in the WEB-INF/classes directory?
That being the question..
the answer to the sample code:
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't done this myself (reading property files from within a .war file but I believe the reason for placing them into WEB-INF/classes is that you can then read the file using ClassLoader.getResourceAsStream(String path)
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saharass,
Thanks for joining JavaRanch.
Unfortunately your name violates our naming policy. Please take a quick look at the rules and edit your profile accordingly.
Thank you!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you include the properties file in the classes directory, it will be in the classpath and you can use the Class.getClass().getResourceAsStream()
 
grapes are vegan food pellets. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic