Java compiler differences cause resources to not be found when Jar'd

I’ve been trying to solve an issue where image resources get properly displayed when running in Eclipse, but do not get displayed when the application is Jar’d up and run from the command line (my stackoverflow original question). I think I’ve ruled out the classpath and relative/absolute resource locations as issues, and have come to the assumption that there must be something significant that is missing from the compiled ‘.class’ files between Eclipse and Gradle.

I Jar’d my application both with Eclipse and Gradle and then extracted the contents of each. All files existed in each ‘jar’ file, however the ‘.class’ files were not binary identical. Is there something that would cause the compiled source files to be different? Would this cause resources to not be located within a ‘jar’ file?

Hello erich, I think the class files differ, because the eclipse IDE uses its own java compiler implementation (Eclipse Java Compiler) and Gradle uses either the ant javac compiler or the compiler api of the installed JDK (depending on gradle version and your configuration). I don’t think that these differences are the cause of your problem.

regards, René

Could it be how the ‘jar’ files are created? I imagine that Eclipse and Gradle use different jar commands as well.

I think its more a problem on how you resolve your paths to the images. When running your project from the eclipse ide, the jar is not created for this. So I think the problem is, that your path resolution works when unpacked resources are used and not when packaged in a jar. IMHO your problem is not related to gradle at all. I would try to solve this with the help of your original stackoverflow thread.

regards, René

I’ve tried every combination of resolving the paths to the images I can think of. When I export a Jar using Eclipse, images show up fine; when Gradle creates the Jar, images don’t display.

I’ve extracted the contents of the Eclipse and Gradle Jars, each contains the same amount files in their respective places. However, when I do a checksum of PNG files they are different. Does that make sense?

If the PNG files are different, then you’re probably filtering them as text when building the jar in Gradle. Perhaps try unpacking the jar and viewing the images in an image viewer, to see if this is the case.