• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

No Graphics when executed from JAR file

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating a program that uses gifs and jpgs as graphics. Those are stored in a folder called "Graphics". When I compile and run my program from the command line, everything is fine. But as soon as I put it in a JAR file and execute it, the graphics don't show. I tried putting the graphics folder into the jar file, but that didn't help.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you currently trying to load the images from the .jar?
 
Marc Beck
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an example how I load the graphics.


When I just compile it and try it out I have the graphics folder in the same folder as the class files and it works. When I put it in a JAR I put the Graphics folder in the same folder as the JAR file and it did not work. Then I tried putting the Graphics folder in the JAR and that did not work, either
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regular file I/O does not work with resources in jar files. You need to use the resource/classloader approach, which will look something like this (assuming that 'Graphics' is a top-level directory in the jar file):
 
Marc Beck
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Ulf.

I will try that out tonight when I get back from work. I will tell you if it works
 
Marc Beck
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it out and it works. Thanks a lot
reply
    Bookmark Topic Watch Topic
  • New Topic