• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic