wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to configure property files in a War? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to configure property files in a War?" Watch "How to configure property files in a War?" New topic
Author

How to configure property files in a War?

bob morkos
Ranch Hand

Joined: Sep 06, 2001
Posts: 104
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.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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 Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
bob morkos
Ranch Hand

Joined: Sep 06, 2001
Posts: 104
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

Joined: May 29, 2003
Posts: 1258
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

Joined: Sep 06, 2001
Posts: 104
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.
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

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.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to configure property files in a War?
 
Similar Threads
How to use Properties file contents
Including property file in the jar
Accessig the properties file from outside the jar file
How to configure property files in a War?
reading config file from JAR file