Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot Find "Properties" File

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a MessageResources.properties file that contains the text to be displayed on the labels and buttons in the form.
Nonetheless, I got HTTP Status 500 and the problem is that the text provided in that file cannot be picked up - I think it results from not finding the file.
I checked:
1. name of the file: it is a correct spelling
2. location of the file: it is in the correct directory
3. type of the file: the Windows Explorer shows the type of that file is a PROPERTIES file
I need your experience to tell what else could go wrong. Please help.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jen,
Are you trying to load the properties file thru a servlet? If so the problem could be that the servlet can't see a file on the host's file system. All it is going to be able to see are files in its virtual path.
Michael Morris
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The properties file is kept in the same directory with all compiled servlet class files.
I am very frustrated by the problem.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[mods: plz move this thread to Servlets forum]
I was totally frustrated with this for a while. I got intermittent behavior and figured out that when I start Tomcat from the directory containing .properties file, it worked. I think it has to do with the classloader finding it in that case.
Fortunately, there's a much better solution than that.
You must use Class.getResourceAsStream() so that tomcat can find the file.
Here's an example:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic