my very first question:
I\'ve been trying to figure this out for a couple of days, but I got to the point I lost my patience. The following are some code and my proj
src
directory is not available in classpath
InputStream imageInputStream = getClass().getClassLoader().getResourceAsStream("resources/icons/xyz.png");
byte[] imageData = org.apache.commons.io.IOUtils.toByteArray(in)
ImageIcon imageIcon = new ImageIcon(imageData, "description about image");
If the png files have been packaged into the JAR in the same locations as they are in the original src directory then
XXX("resources/icons/xyz.png");
should produce the right result.
Normally when exporting a JAR file from Eclipse, the contents of src/resources
are exported minus the src
path name itself. To get the image to load from your JAR you could do:
InputStream stream = getClass().getResourceAsStream("/resources/icons/xyz.png");
ImageIcon icon= new ImageIcon(ImageIO.read(stream));
One way to know for sure is to check:
jar tvf yourjar.jar