aspose file tools*
The moose likes Java in General and the fly likes No Graphics when executed from JAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "No Graphics when executed from JAR file" Watch "No Graphics when executed from JAR file" New topic
Author

No Graphics when executed from JAR file

Marc Beck
Ranch Hand

Joined: Sep 09, 2006
Posts: 36
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

Joined: Jan 17, 2006
Posts: 1296
How are you currently trying to load the images from the .jar?


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Marc Beck
Ranch Hand

Joined: Sep 09, 2006
Posts: 36
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
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
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):


Ping & DNS - updated with new look and Ping home screen widget
Marc Beck
Ranch Hand

Joined: Sep 09, 2006
Posts: 36
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

Joined: Sep 09, 2006
Posts: 36
I tried it out and it works. Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: No Graphics when executed from JAR file
 
Similar Threads
Cannot run .jar file
writing to jar file
Dependecies in JAR file
Saving application settings
Accessing text files outside eclipse