Re: reading GIFs from a JAR file

<cebmailbox-trijug-/[email protected]>
Newsgroups gmane.org.user-groups.trijug.juglist
Message-ID <[email protected]>
I find this always works, jar or no jar:
   
  ImageIcon DNA_ICON = new ImageIcon(
              Object.class.getResource("/view/gifs/DNA18x28.gif"));
   
  Note:
  1.
  If this call is in an instance method feel free to replace "Object.class" with "this.getClass()".

  2.
  Note that graphic file can now be "absolutely" pathed if you start the path with "/", or relatively pathed if "view" is a sub-directory (sub-package) of the class where this code is located.
   
  For instance if this code is in an instance method of a class in the package:
    test.gui
  and the graphic is in:
    test.gui.view.gifs
  then you may do:
   
  ImageIcon DNA_ICON = new ImageIcon(
              this.getClass().getResource("view/gifs/DNA18x28.gif"));
   
   
  -Chris

Richard Hammer <[email protected]> wrote:
  I am trying to read GIF files from a JAR. The GIFs are in a 
subdirectory in the JAR. This JAR also contains our class files in 
other subdirectories. This JAR is in the classpath, and classloader is 
finding the class files.

But the GIFs are not being found. I had thought I would be able to read 
the GIF files with code like this:
ImageIcon DNA_ICON = new ImageIcon("view/gifs/DNA18x28.gif");

where "view/gifs/DNA18x28.gif" is the path of the GIF in the JAR.
But this is not working for me.

What I find with Google suggests that I may need to open a 
java.util.jar.JarInputStream, from which I can read JarEntry(s) while 
looking for my specific GIF file. Is it really that hard? Is there an 
easier way?

Thanks,
Rich Hammer

_______________________________________________
Juglist mailing list
[email protected]
http://trijug.org/mailman/listinfo/juglist_trijug.org

_______________________________________________
Juglist mailing list
[email protected]
http://trijug.org/mailman/listinfo/juglist_trijug.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.