Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem accessing file from jar file in Java

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

like image 502
Ankit Avatar asked Feb 24 '26 10:02

Ankit


1 Answers

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

like image 130
Wes Avatar answered Feb 27 '26 01:02

Wes