Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to configure property files in a War?

 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • 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.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic