Results 1 to 7 of 7
Thread: Images in .jar File
- 02-09-2013, 10:33 PM #1
Member
- Join Date
- Feb 2013
- Location
- San Diego
- Posts
- 63
- Rep Power
- 0
Images in .jar File
I have a program which uses images. It works fine when I execute the program, but when I clean+build and run the jar file - no images.
I added an images folder. The pics are in it: "...Documents\NetBeansProjects\Flip Game\src\flip\game\pics".
How can I bundle the images in the jar file?
-
Re: Images in .jar File
The images are likely already in the jar file. Have you used an unzip program such as 7-zip to check it? The key will be how to access them. Remember that files don't really exist inside of a jar file, and so you'll need to access the images as resources using a path that is relative to the class files.
- 02-10-2013, 02:59 AM #3
Member
- Join Date
- Feb 2013
- Location
- San Diego
- Posts
- 63
- Rep Power
- 0
-
Re: Images in .jar File
I've usually used the ImageIO class's static read(...) method. It can take an InputStream, and you can get one from your class or class loader and use that. For instance, if you're in non-static land, for instance inside of your class's constructor, you could try something like
Java Code:try { BufferedImage img = ImageIO.read(getClass().getResourceAsStream("flip\game\pics\myImage.jpg")); } catch (SomeExceptionIForgotWhat e) { e.printStackTrace(); }
- 02-10-2013, 06:13 AM #5
Member
- Join Date
- Feb 2013
- Location
- San Diego
- Posts
- 63
- Rep Power
- 0
Re: Images in .jar File
Sorry but I'm very new to Java (and programming in general) and I don't understand what you said. What method(s) should I use and where exactly should I use them?
Thanks much
-
Re: Images in .jar File
It's hard to say without knowing more about your code, your problem, the structure of your jar file....
You will want to experiment with your code of course -- it's hard to break your computer by doing this, and if that fails, then show us more and tell us more.
- 02-10-2013, 06:20 AM #7
Re: Images in .jar File
This may help: Loading Images Using getResource
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Get PDF File as Images & Extract Text from Images Using REST APIs
By saaspose in forum Java SoftwareReplies: 0Last Post: 11-14-2012, 11:15 AM -
how to convert doc file containing images and tables to pdf
By webcraft in forum New To JavaReplies: 9Last Post: 07-28-2010, 11:27 AM -
How do I store images in a zip file in Java
By mglover in forum Advanced JavaReplies: 1Last Post: 06-11-2010, 03:53 PM -
How to add images to a .jar file?
By dunafrothint in forum New To JavaReplies: 3Last Post: 03-05-2010, 07:38 AM -
Images in JAR File (via Eclipse)
By AndrewM16921 in forum New To JavaReplies: 13Last Post: 10-08-2009, 06:31 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks