java - Can't load resources file from jar -


i'm using configuration json file stored in src/test/resources/config.json.

i'm getting this:

string configfile = this.getclass().getresources("config.json").getpath(); 

i have getpath() method, because need string value, check if file exists , parse it.

in eclipse ide works fine, because parse file /bin/config/config.json, when create jar file, path program.jar!/config/config.json , function !files.exists() returns false.

how can resolve issue?

instead of referencing file it's path, when use resources loader should open file's inputstream.

instead of .getresources("config.json").getpath();

try using this.getclass().getresourceasstream("config.json"); if stream returned null resource not exist.

this way if resource packed jar, classloader return correct thing.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -