Java w/ maven : getting sources from a jar file -


i write gui app , , use image files (gif) icons. when run app in ide - icons appear. when run jar - fail (null pointer exception on resource)

the package structure following:

code : src/main/java/com/my/app

resources : src/main/resources/com/my/app

i wrote little example:

       url url ;          url = guiutils.class.getresource("/com/my/app/gui/fading_lines_blue_64x64.gif");         system.out.println("url: " + url);          url = guiutils.class.getresource("/resources/com/my/app/gui/fading_lines_blue_64x64.gif");         system.out.println("url: " + url); 

when ran ide:

url: file:/c:/repositories/v8/trunk/myapp/build/com/my/app/gui/fading_lines_blue_64x64.gif url: null 

when ran jar:

url:null url:jar:file:/c:/devenv/projects/viewer/testpicload.jar!/resources/com/cmy/app/gui/fading_lines_blue_64x64.gif 

i solved , it's not right way it:

public static url getresourceurl(string path) {              url url = guiutils.class.getresource(path);         if (url == null) {             url = guiutils.class.getresource("/resources"+path);         }         return url;     } 

suggestions?

the path sounds wrong in second option. default maven should put resources target/classes along compiled classes. jaring should take of thats why adding "/resources" sounds odd me. should finding gif in testpicload.jar!/com/cmy...

are doing odd when create jar?


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -