Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Properties file location.

 
Rajul King
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seema
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Regards
Seema
 
Bill Pearce
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
WEB-INF/classes/com/myname/test
folder.
 
hanumanth reddy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put your *.properties file in the WEB-INF/classes directory
Hanumanth Reddy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic