Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading property file in a jar file

 
Eileen Chong
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jar file going to be deployed in the web application web-inf\lib directory. However, one of the method that reading configuration value from a property file distributed together in the jar file fail to read the property file. It was pointing to the windows\system32 direcotry if i access it via jsp but it works fine if i run it standard-alone. Any way to work around this as this jar file should be self-provide classes, no configuration value should be passed in as argument.
I am using tomcat 4.1.2. Will it have the same problem if i deploy in other web container such as Webshpere? Any way to make it works across different web containers? Thanks in advance for any reply.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's probably because you are trying to load the properties file from the file system?

Re-write that code to use a classloader.getResourceAsStream() method.
 
mshravan kumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Curwen wrote:That's probably because you are trying to load the properties file from the file system?

Re-write that code to use a classloader.getResourceAsStream() method.


Thanks Mike. I got around this problem and your solution helped me.

Shravan Kumar.M
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic