Santi Agüero
Santi Agüero

Reputation: 3133

Java - Maven - Setting Icon Images in a Form

I've a maven project where there is a JFrame and I want to set up Frame's icon image so as buttons' icon images.

My icon images lives into a package com.foo.bar.frame.images. I have set up correctly buttons' icon images but when I run the maven project it will hesitate with this:

SEVERE: null
java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
        at com.intel.jiratool.jiraexcelclient.view.ExcelView.initComponents(ExcelView.java:119)
        at com.intel.jiratool.jiraexcelclient.view.ExcelView.<init>(ExcelView.java:40)
        at com.intel.jiratool.jiraexcelclient.Main.main(Main.java:54)

Line 167:

btnClose.setIcon(newjavax.swing.ImageIcon(getClass().getResource("/com/intel/jiratool/jiraexcelclient/view/images/32px-Crystal_Clear_action_exit.png"))); // NOI18N

Moreover, when I go to the target folder where resides the jar file, if I inspect it, there aren't any images.

How can I get working this situation? Maybe including something in the maven's POM file?

Best Regards,

Santiago.-

Upvotes: 1

Views: 3862

Answers (1)

ptomli
ptomli

Reputation: 11818

Where in the Maven source/resource paths do the images reside?

I suspect

/src/main/resources/com/foo/bar/frame/images

If your POM is setup to produce a JAR like package, unzip -l target.jar would show you if the images are indeed in the JAR(thing) at the correct location. This would indicate if it's a Maven problem (by not including the images in the package) or a runtime problem (by not loading the images from the correct location).

Indicate where you're putting the images, ensure the images are in the package, and indicate how you're specifying the image location at runtime.

Upvotes: 3

Related Questions