• 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 configure property files in a War?

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I deployed the war file and the application performed wonderfully fine. The problem is, one functionality in my application uses a property file (abc.properties) which is stored under a created folder "conf". This property file is embedded in the default.war. But, my java code which loads the properties file (using the Java Properties class), gives "FileNotFoundException".
My question is, is it required to include my application specific properties file in the web.xml file? If so, how do i do it?
why is my Java code not able to read my properties file (abc.properties)?

Any help will be appreciated.
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use the functions provided by java.lang.ClassLoader to do this sort of thing. Time to go read those API docs.
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it and it did not work. Could you direct me to the right path. This is the only feature missing in my application. I can't seem to load that property file, but it works fine if I put it in the src folder. Any help would be grateful.


Originally posted by Nathaniel Stoddard:
You need to use the functions provided by java.lang.ClassLoader to do this sort of thing. Time to go read those API docs.

 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um ... the functions I'm talking about in java.lang.ClassLoader don't throw FileNotFoundExceptions. So, are you really using the right ones? Why don't you tell us the pathname of the property file that's in your WAR, and the code snippet you're using to open it.
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Webroot contains folder directory src,WEB-INF, config

My prop file "abc.txt" directory is under config folder

Manifest:
ClassPath: config/abc.txt

Java code:

Properies prop = new Properties();
InputStreamReader in = null;
try {
in = new InputStreamReader(Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream ("abc.properties")));
props.load(in);
} catch (FileNotFoundException e) {
System.out.println("FileNotFoundException: " + e.getMessage()):
}


I keep on getting FileNotFoundException




Originally posted by Nathaniel Stoddard:
Um ... the functions I'm talking about in java.lang.ClassLoader don't throw FileNotFoundExceptions. So, are you really using the right ones? Why don't you tell us the pathname of the property file that's in your WAR, and the code snippet you're using to open it.

 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you see the reply to your original thread that I moved to the servlets forum? here.

I'm moving this thread to the servlets forum as well -- seeing as though this question is specifically about a web application. Please post your replys there, thanks.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, if i am not wrong. You name your file as .txt and opening stream to .properties file.
That error might persist, move your file to the same directory where your class is located.
[ April 16, 2005: Message edited by: Adeel Ansari ]
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic