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
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
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
why should you?
Do read the documentation of the method. Its parameter is relative to the classpath, not an actual path on the filesystem.
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