This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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

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: 2372
Read the section from the Swing tutorial on How to Use Icons.
Have you checked out Aspose?
subject: Accessing images in a jar file
It's not a secret anymore!