File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Reading image file from executable jar" Watch "Reading image file from executable jar" New topic

Reading image file from executable jar

Mihai Popa

Joined: Dec 04, 2011
Posts: 5
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 " 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

Joined: Oct 27, 2005
Posts: 19905

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

How To Ask Questions How To Answer Questions
Paul Clapham

Joined: Oct 14, 2005
Posts: 19330

Jay Brass,
Your post was moved to a new topic.
It is sorta covered in the JavaRanch Style Guide.
subject: Reading image file from executable jar