Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Images in a JAR

 
Andrew Honma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using images as textures in a small program I'm playing with.

When I create a the JAR file, I include the images (I am using Eclipse, and have the image files check-marked).

However, running the JAR fails to load those images.

The images load just fine when the program is run within the Eclipse IDE.

I am using images with java 3D, for example:



The images are currently saved under the Project_Name directory:

Project_Name
|
|_src (folder)
|image_name.xxx

However, moving the images around and changing the path will continue to allow it to work in the Eclipse IDE but not when exported to a JAR.

Please let me know if any more info needs to be supplied to help with this.

Thanks.
[ July 19, 2008: Message edited by: Drew ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Drew," welcome to JavaRanch! Please check your private messages by clicking on My Private Messages. Thanks!
 
Norm Radder
Bartender
Posts: 1224
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the images are in the jar file and NOT on disk, you need to access them using classes/methods that know how to look in a jar file. I don't know about the TextureLoader class.
You can use the getResourceAsStream() method to read the image.
Check the constructors for TextureLoader to see if it can get its input from another source.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic