wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Can't Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can Watch "Can New topic
Author

Can't "see" image inside the jar file

Orna Vel
Greenhorn

Joined: Jun 02, 2003
Posts: 12
Hello,
I created the .jar file for distribution. There are some .class files there and an Image directory with several .gif files I use as icons.
I run the application with the command:
java -classpath ".;MyJar.jar" MainClass
Everything runs fine, but there are no icons on my GUI :-(. It works fine if I copy the Image directory to current directory (.). But I do not want to do it.
When I use
jar -tf MyJar.jar I can see, that Image directory with all gifs is there.
How can I avoid copying the Image directory?

Thank you.
:roll:
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
You need to use one of the getResource... methods.

usually that would go something like
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As Steven suggests, the problem is probably with the methods you use to load the images. If you can post the code that does this, we can help give more specific suggestions how to fix it. I think Steven's suggestion for using the getResource() methods will probably help. If not please post some code so we can help further. You should also google for more information about using resources in Java.

Layne


Java API Documentation
The Java Tutorial
Orna Vel
Greenhorn

Joined: Jun 02, 2003
Posts: 12
Thank you so much, gurus. My code looks like this:


etc.

Where:

I'll try to find another way to deal with this names.
[ May 25, 2005: Message edited by: Orna Vel ]
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
You should be able to fix it by changing this line

to
Orna Vel
Greenhorn

Joined: Jun 02, 2003
Posts: 12
Thank you, it works now.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't "see" image inside the jar file