When I export my Java application as an Executable JAR file, it seems that the images are not exported. In fact, I can not see the images on the UI.
There are two solutions for solving this problem:
Solution #1
I add the folder containing the resources into the folder where the JAR file has been created. Then, I make sure that the directory matches the path I mentioned in the application.
Solution #2
I want the resources to be directly included in the JAR file. I need to use the function getResource() to get the images, and then make sure that resources are visible in both: "/src" and "/bin" folders.Let's take an example:
- Application code:
ImageIcon myIcon = new ImageIcon( this.getClass().getResource("/resources/icon.gif"));
JComponent myComponent = new JComponent();
myComponent.setIcon(myIcon);
...- Locations where the file should be visible:
/myApp/src/resources/icon.gif
/myApp/bin/resources/icon.gif
Finally, export your application... and enjoy!
Not working...
ReplyDelete