I have a maven project in eclipse with App.java
in in my.package
in src/main/java
and a couple of pictures in my.package.resources
I looked in the jar and the structure is like this:
MyApp
|- chrriis \\ library stuff
|- com \\ stuff with google and sun
|- javax
|- META-INF \\ contains MANIFEST.MF and other maven stuff
|- org \\ contains most of my used libraries
|- my
| |- package
| | | App.class
| | | App$1.class
| | |- resources
| | | |-picture.png
When I load a picture like:
JPanel p1 = new JPanel(new GridBagLayout());
p1.add(new JLabel(new ImageIcon(App.class.getResource("resources"+File.separator+"picture.png"))));
and run it in eclipse, it works fine. But when I Export it to a runnable jar it give me this error:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
...
But when I move the picture.png to my.package
and do
App.class.getResource("picture.png")
it works fine.
I tried this four solutions but they did not work for me: (1) (2) (3) (4)
Any help would be appreciated.