This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Reading image file from executable jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Reading image file from executable jar" Watch "Reading image file from executable jar" New topic
Author

Reading image file from executable jar

Mihai Popa
Greenhorn

Joined: Dec 04, 2011
Posts: 5
Hello!
I have built a small Swing application that wants to resemble to a GIS application.

There is a problem when i try to load an image file (jpg):
-When i run the project from Eclipse, loading a larger image (18000 px) using "ImageIO.read(new File(...))" takes 3 second and starts the fan of my computer.
Anyway, the image is loaded succesfully
-When i try to do this from an exported "runnable jar" of my app, the image doesn't load anymore. The "runnable jar" loads correctly smaller images.

Can you tell me what is the problem?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

For files inside ZIP or JAR files, you can no longer use java.io.File and its matching stream / reader / writer classes. Instead, you should use Class.getResource, Class.getResourceAsStream, or the same methods from ClassLoader.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Jay Brass,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading image file from executable jar
 
Similar Threads
executable jar file
Jar file issue
ImageIcon's not displayed when created a executable Jar.
Slow images in jar
My Program is not loading the image files in the jar.