• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Properties file location.

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
put your *.properties file in the WEB-INF/classes directory
Hanumanth Reddy
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic