• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading a property file in Web application (Eclipse + Lomboz)

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using Lomboz3.1.2 for Web application development using eclipse.

I have created a property file containing some configurable parameters like the database driver, URL, etc. But when I try to load this file [ Properties.load (fileInputStream) ... ] it always throws the FileNotFoundException.

I tried putting this property file in the WebContent folder, in the WEB-INF\classes folder, but everytime it throws the exception. What would be the right location for this file?


Thanks,
Ankit
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has someone tried this kind of thing?

Any help would be greatly appreciated.


Thanks,
Ankit
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a web application there is no "current directory" so you cannot load files from a "relative path". If you really want to load something from a File, you need to specify the full path (on Windows that might be C:\software\projects\wibble\src\config\stuff.properties or whatever.)

This is obviously dangerous - this is probably not where the properties file will be located on the live server.

A better way to read such information is using Java's "resource" mechanism. Place the file in WEB-INF/classes and load it as a "resource" using something like:



Does that help?
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah this is a good idea, I will surely give it a try.

Maybe I can also try the java.util.ResourceBundle class.


Thanks,
Ankit
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The java.util.ResourceBundle worked for me. I put the property file under the WEB-INF/classes and used with ResourceBundle and it worked for me!!


Thanks again,
Ankit
reply
    Bookmark Topic Watch Topic
  • New Topic