This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one 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
Author

Accessing images in a jar file

Ali Yuruz
Greenhorn

Joined: Oct 10, 2007
Posts: 8
Hallo,
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
-classes
-images
-META-INF

The code to read images is like:


Help!!!

SCJP
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10699
    
    9

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
Greenhorn

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

Thanks.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2296
    
    8
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