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
Post a Comment