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!
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