I have an issue with my software, when building and running it as an FatJAR/UberJar built with Maven. In this case I get this error:
Uncaught error fetching image:
java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:686)
at java.util.zip.ZipFile.getInputStream(ZipFile.java:366)
at java.util.jar.JarFile.getInputStream(JarFile.java:452)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:164)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:127)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:263)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
However, the software works correctly, when launched directly from IntelliJ.
I have created a minimal example to reproduce the error here:
https://github.com/michaelmell/bugfix_003-ImageJFunctions_show-call-fails-in-UberJar
The issue somehow has to do with this call (please see the Git repo for full code):
ImageJFunctions.show(input);
I suspect that I need to adjust the shading in pom.xml
, but I am too unfamiliar with the configuration.
Please see the pom.xml
and deploy.sh
for details on how the JAR is built and the shading is done.
I have also stepped into the JAR using IntelliJ and set a break point in the dependency URLImageSource::getDecoder
to check the URL that fails. It is:
/PATH/TO/THE/GIT/REPOSITORY/target/ImageJFunctions_show__failure_minimal_example-1.0-SNAPSHOT.jar!/icons/imagej-256.png
which exists in the JAR the file: icons/imagej-256.png
. Note that this is an icon, that is part of the imagej dependencies (not one that I introduce).
I don't really know what to try next and would welcome any suggestions!