java - Loading Properties File from Static Context -
i've found myself faced pretty interesting issue. have properties file in application, , attempting load static context. properties file loaded class image, static class. in eclipse works fine, when tried export jar, it's not worked.
prop.load(new fileinputstream(new file(images.class. getclassloader(). getresource("config.properties"). tostring()))); this line i've tried use already, when try run program, throws error:
exception in thread "main" java.lang.nullpointerexception @ controllers.images.loadimagefiles(images.java:47) @ views.world.<init>(world.java:55) @ views.world.main(world.java:40) i @ loss here, question is:
how load resource static context, , more importantly, need register file resource before this?
edit
after searching, i've established getresource method returning null. big question now, guess, why!? file structure follows:
project src controllers <-- images class is. models views img doc config.properties <-- file want. i'm not entirely sure how i'm stuck answers.
put properties file in same directory class , use getresourceasstream() method instead. return inputstream there no need construct file. continue work if package classes in jar...
properties prop = new properties(); prop.load(images.class.getclassloader().getresourceasstream("config.properties")); or static context:
prop.load(classloader.class.getresourceasstream("config.properties"));
Comments
Post a Comment