ChrisFreeley
ChrisFreeley

Reputation: 1

Adding images to a JAR file in Eclipse?

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

Upvotes: 0

Views: 2075

Answers (2)

chmod222
chmod222

Reputation: 5722

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 :)

Upvotes: 0

Jeff Storey
Jeff Storey

Reputation: 57192

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.

Upvotes: 3

Related Questions