Accesing properties file in web application

I have properties file under my web application context say /myapp

I am trying to access the same through some java bean

File f = new File("abc.txt")

I get FileNotFoundException. can pointers can be useful

[231 byte] By [oliver_fernsa] at [2007-11-27 11:40:41]
# 1

Use servlet.getServletContext().getResource(java.lang.String path)

or getResourceAsStream(java.lang.String path)

See http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html

java_2006a at 2007-7-29 17:33:19 > top of Java-index,Java Essentials,Java Programming...
# 2

for that I will have to pass the context to the JavaBean which I want to avoid...any other way?

oliver_fernsa at 2007-7-29 17:33:19 > top of Java-index,Java Essentials,Java Programming...
# 3

why should you?

Do read the documentation of the method. Its parameter is relative to the classpath, not an actual path on the filesystem.

jwentinga at 2007-7-29 17:33:19 > top of Java-index,Java Essentials,Java Programming...
# 4

Its is application.properties file which I use for configuration purpose of my web application.It is read through some utility class which stores the information in memory so that it is available at any places where configuration information is needed. I dont want to package it under any jar file in the begining. It will be located outside my jar file. A utility class in the jar file would read this config information. The problem is accessing this file when it is under a web application.

Btw, I tried the following, this.getClass().getResourceAsStream("/application.properties"); It worked but for this I have to package it under the jar file. Which is not what i want

I need it outside the jar file

My directory structure would read like

/myapp

application.properties

/WEB-INF

/classes

/lib

utility.jar

Later this jar would be moved in some tomcat/shared/lib along with the properties file for my other web applications

oliver_fernsa at 2007-7-29 17:33:19 > top of Java-index,Java Essentials,Java Programming...