wood burning stoves 2.0*
The moose likes Java in General and the fly likes Accessing images in a jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing images in a jar file" Watch "Accessing images in a jar file" New topic

Accessing images in a jar file

Ali Yuruz

Joined: Oct 10, 2007
Posts: 8
At first I must say, Everything works in Eclipse.

I generate a jar file with Ant. When I start the program i doesn't find the images.

I do it like:
In eclipse there are two folders. One is src (for java files). The other is images(for images).
I put the classes and images in jar file with the following structure

The code to read images is like:


Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167

Resources inside jars should be accessed using getClass().getResource() or getClass().getResourceAsStream()

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ali Yuruz

Joined: Oct 10, 2007
Posts: 8
How will be the code for my case??

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
Read the section from the Swing tutorial on How to Use Icons.
I agree. Here's the link: http://aspose.com/file-tools
subject: Accessing images in a jar file
Similar Threads
how do you load images from a jar file for image buttons?
images in jar file
Problems with Image Icons in Forte 3.0
Icons and Images question
jar file probelm