Images in Jars

"How do I get images out of a jar file?" is a Java FAQ.

After searching the net there appeared to be a dearth of ready-made solutions that actually worked.

There were many different problems - the issue can appear to be a little like a can of worms.

This page presents the resource I was looking for when I first had to implement this functionality.

My solution is in the form of a class file (called the ImageLoader class) which is designed to handle loading images. It loads images from a jar file - or directly from the filing system - whichever is most appropriate.

There is also a new ImageLoadingManager class, which can be used to speed up the loading of images, if it is necessary to ensure images are loaded before using them.

See the instructions in the comments at the top of this file for details of how to use it (or refer to the javadoc).

Because of problems with Netscape there can be difficulties in finding a fully portable method of getting access to images within jar files. The solution on that page doesn't appear to work properly if multiple images are requested. The method described here fixes that - and should work in most places.

Resource Index

  1. ImageLoader class
  2. ImageLoadingManager class
  3. Test class
  4. The gif
  5. The jar (made with "jar cf test.jar *.class *.gif")
Here is the javadoc for the classes.

Test applet

Unfortunately, your browser does not support Java.
A Java applet is the central focus of this page.
You're encouraged to try again using a Java-aware browser.


Index | Links

tim@tt1.org | http://mandala.co.uk/