• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No Graphics when executed from JAR file

 
Marc Beck
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I tried it out and it works. Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic