Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

file property problem II

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Why is that when I code:
InputStream is = MyClass.class.getClassLoader().getResourceAsStream("my.properties");
This returns null when my application is runnign as a NT service? Is there another way of getting the path to MyClass?
Thanks in advance!
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you putting the file "my.properties"?
Your code will look in the current directory, which I guess in NT is System32. Try fully qualifying your filename, or use getSystemResourceAsStream()
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code posted will not necessarially look in the current directory. It will look at the same ClassLoader that loaded MyClass. So my.properties should be in the same location (classpath entry) as MyClass.
For example, if MyClass is com.foo.MyClass and is in mystuff.jar then the my.properties file should be in mystuff.jar also.
If MyClass is in a directory like /home/devel/classes/com/foo/MyClass.class, then my.properties should be at /home/devel/classes/my.properties.
If you put them in the same place, then this will always work - if the ClassLoader can load MyClass it should also then find my.properties.
 
Water proof donuts! Eat them while reading this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic