Search code examples
imagejavafxjava-web-startjavax.imageio

ImageIO no suitable reader in Java web start


I have a java web start application that shows some png images that are loaded with:

InputStream is = AClass.class.getClassLoader().getResourceAsStream(“icon/tray.png”); 
ImageIO.read(is);

While this works perfectly from Eclipse it doesn’t work when I run the application with Java web start. Obviously the difference in both setups is that in Java web start the image will be loaded from a jar file while in Eclipse the images comes directly from the file system.

What happens in Java web start is, that the InputStream gets created as expected (meaning the resource can be loaded) but, as far as I can see it, within the ImageIO.read() method no suitable reader can be found for the image in the stream and ImageIO.read() returns null. How can it be that a reader can be found when starting from Eclipse but not if started with Java web start?

Furthermore I got some more png’s that are loaded with mechanisms from JavaFX more precisely via css e.g.

-fx-image: url('icon/settings_general_32x32.png');

I see the same behavior here too. It works from Eclipse but not with Java web start although I’m not sure if this is because of the same reason or even for another reason but I would guess that it is because of the missing reader too.

So I looked in the code of PNGImageReaderSpi and there one can see in the method canDecodeInput() that the first 8 byte of the stream will be analyzed to decide if the PNG reader can decode the image or not. So I had a look at the first 8 bytes of the image stream when starting from Eclipse and when starting from Java web start and indeed there is a difference. When running from Eclipse the first bytes are -119,80,78,71,13,10,26,10 and in Java web start the first bytes are -17,-65,-67,80,78,71,13,10. For me this looks at least a little strange, but I’m not sure if that is the cause of the problem.

Has anybody come across this problem? Did I miss anything? Any help or ideas are highly appreciated.


Solution

  • As writen in the comment the images where currupted by the applications build script. This was the reason why it was not working with Java web start but was working from Eclipse where the build script was not used.