-1
\$\begingroup\$

I've been searching for days. When I export and create my fat jar it loads and disappears. It can't find my images.

enter image description here

This is what it all looks like. I used something like this to load them:

File a;
a = new File("res/theimage.png");

   wood = TextureLoader.getTexture("PNG", new FileInputStream(a));

This works just fine in eclipse but the jar can't find the image. I tried putting the first jar with the fat jar in a folder. It still didn't work so I put all project files in there too. Somehow it couldn't find it still. How do you get your res to be in your lwjgl game. I mainly just want to have a jar file that you click and start easily instead of a zip folder with all the files. I don't know how to do any of this. My game without images works just fine. I rather a visual way of doing this.

Can Images be draw without being textures in LWJGL?

\$\endgroup\$
2
  • \$\begingroup\$ How is this question different from your previous question? \$\endgroup\$
    – msell
    May 11, 2014 at 16:45
  • \$\begingroup\$ I figured it out \$\endgroup\$ May 11, 2014 at 21:43

1 Answer 1

0
\$\begingroup\$

Files embedded in jars are not "files" in the java File object sense, that's why it works just fine when running from Eclipse but not from a Jar. Jar files are zip files. To actually use a file embedded within a jar (a zip file) the file must be decompressed first. You're going to have to extract the images from the jar to the local harddrive when running your game or open your image files as InputStreams.

See https://stackoverflow.com/questions/15423560/java-how-to-use-an-image-within-a-jar-file, https://stackoverflow.com/questions/12437752/loading-images-in-a-jar, and Java getResourceAsStream as local resource for examples.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .