3

I have a jar called App.jar and it's structure is as follows

App.jar
    |
    |
    |---xyzfolder
    |       |
    |       |--config
    |            |
    |            |--config.properties 
    |  
    | 
    |---com (contains classes)
          |
          |--MyClass.class

Now what I want is that I want to access config.properties file from MyClass.class

Wes
  • 6,697
  • 6
  • 34
  • 59
Ankit
  • 2,753
  • 1
  • 19
  • 26
  • 1
    I've tried getClassLoader().getResources("config.properties") which gives nullpointerexception error. – Ankit Apr 26 '11 at 11:35
  • Thats because you need to specify the path. Its not in the same package – Wes Apr 26 '11 at 11:41

1 Answers1

1

Have you tried the following?

this.getClass().getClassLoader().getResourceAsStream("classpath:/xyzfolder/config/config.properties");

see http://download.oracle.com/javase/1.5.0/docs/api/java/lang/ClassLoader.html#getSystemResourceAsStream%28java.lang.String%29

Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
Wes
  • 6,697
  • 6
  • 34
  • 59