java - Getting a resource in a another package from within a jar -
ok, know question asked lot, solutions found did not work. i'm making application in netbeans uses custom font. program runs fine in netbeans 0 errors. when netbeans cleans , builds jar , run command line with:
java -jar myproject.jar the program returns nullpointerexception on following line:
try { font = font.createfont(font.truetype_font, getclass().getresource("/fonts/raleway-extralight.ttf").openstream()); //<--this line } catch (fontformatexception | ioexception | nullpointerexception e) { system.out.println("error creating font: "+e); system.exit(1); } i've tried many different solutions such as:
getclass().getclassloader().getresource(); but not work. i've never used streams before, , feel may have recode major part of program if have use them (i'm loading lot of images well, don't know if work). have code in 1 package , fonts , images next in own packages. answers welcome. i've started programming , appreciate help. in advance!
(edit) wanted did more debugging , found location of font null.
ok, think i've solved it. default, if no classpath set, classpath set default folder run command. means program looking font in folder contains jar, incorrect location font in jar. can set classpath command line -cp, , folder , files (including external jars), separated colons (;). problem unrelated code.
Comments
Post a Comment