File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring forum!
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: 10451
    
    8

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