views:

163

answers:

2

I'm trying to make a game in java, but I'm a bit of a newb. The game has images, and when I run the application from eclipse, they all show up fine. But when I export the project as an application, the images don't show up. When I put the application in the same folder as the images, they show up when I run the application, so someone suggested that I just need to put the image files inside my JAR. Can someone tell me how? Thank you

+3  A: 

To load files from a jar you need to use getResource or getResourceAsStream from Thread.currentThread().getContextClassLoader(). Alternatively, you could create a zip file with your application and actually have the images outside the jar and load them from the file system the way you do currently.

Jeff Storey
Here's a good guide for something like this: http://www.devx.com/tips/Tip/5697
Andy White
A: 

I don't know how this works in practice, but I know you can extract JAR files. I think they're also just ZIP files with a .jar extension.

So, just extract it, put your image in and pack it again :)

LukeN
This answer is misleading. This is not the way JAR files are intended to be used. You can load them directly from the JAR as described above without explizitly unpacking them.
Arne