wood burning stoves
The moose likes JSP and the fly likes Properties file location. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Properties file location." Watch "Properties file location." New topic

Properties file location.

Rajul King
Ranch Hand

Joined: Apr 12, 2001
Posts: 47
I have created a simple java class that uses a properties file to read certain parameters. I then put this java class in the /WEB-INF/classes and the properties file in the /WEB-INF folder. It works fine when I run it on command line but when I try to access its results in a JSP, it throws an exception "Properties file not found".
Did any one come across this kind of problem before.
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
I think .properties files probably go in the root. But I bet you can set the location by configuring your servlet container (you didn't say which servlet container you were using).
Try something like the following:
File myFile = new File( "MyProperties.properties");
System.out.println( myFile.getAbsolutePath());
That will tell you where to put the file.

Joined: Aug 05, 2002
Posts: 15
If the property file u r using is name value pair , then u can use resource bundle to read ur property file.U can place ur property file anywhere within ur project package hierachy and read it.
e.g ur property file name is abc.properties
and it is in package : com.properties
Code :
// Code to load property file
java.util.ResourceBundle rboResourceBundle = java.util.ResourceBundle.getBundle("com.properties.abc");
// code returns the value read from a property file of a given key.
public String getPropertyValue(String keyName) {
return rboResourceBundle.getString(keyName);
I hope this will help u.
Bill Pearce
Ranch Hand

Joined: Sep 19, 2000
Posts: 53
The Properties class makes this quite easy. Use this snipit when you want to place the properties file in the classpath. This can be a folder in your /WEB-INF/classes folder, or the common/classes folder off Tomcat root (assuming you are using Tomcat).

For the above, you would place the PropsFile.properties file in the
hanumanth reddy
Ranch Hand

Joined: Jun 12, 2000
Posts: 118
put your *.properties file in the WEB-INF/classes directory
Hanumanth Reddy

<a href="http://www.jobklub.com" target="_blank" rel="nofollow">http://www.jobklub.com</a><br /> 'Add Job To Life'
I agree. Here's the link: http://aspose.com/file-tools
subject: Properties file location.
jQuery in Action, 3rd edition