Game works in eclipse, but...

Hey guys, I just made my first basic java game, which is just a 2D, pong type shooter. It works if I run it in Eclipse, but when I export it too a .Jar it won’t load any of my graphics.

Is it maybe my graphics aren’t being exported? I selected export and compress files into jar at the option screen, but no luck.

If anyone can help me that’d be great!

I have the same problem except in LWJGL. are you using Java2D for your game?

Nope, just using JFrame!

Are you loading your images from files or ressources?

If you want to check whether the graphics are in the jar or not, either use jar tf at the command line or rename it to .zip and open it with your favourite unzipper.

But the typical problem here is getting the structure for the resource path wrong. If you want help debugging, it would be useful if you post the relevant snippets of code, the relevant snippets of the jar structure, and the exception message.

show as A) your folder structure and B) how you load it

Ah yes, the pictures aren’t being added. I’m calling them in via locally using a folder in eclipse. Anyway to solve this?

Place them in a package (or the default one) and load them via

ClassLoader.getSystemResourceAsStream("path/to/file/inside/jar")

Or create a folder with the images next to the jar, named as the original folder.

Do you know the exact location of that folder? It would be something like C:/Users/OwnerName/eclipse/workspace/folderName /TheImage.png

Someone posts this same problem about every other day.

In short: use .getResourceAsStream(…), don’t use new File(…), it won’t work when your project is a jar.

Google getResourceAsStream() for usage, special cases, etc.

Don’t ever use absolute paths in an application.