This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jar file help please

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jar cmvf manifest.txt jahok.jar *


why wont it keep my images in the jar file, if my jar is in the same folder as the images they show up, but when i move the jar to desktop , it doesnt draw, or read from files its supposed to...

Thanks,


Justin
[ February 05, 2007: Message edited by: Bear Bibeault ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you use Class/ClassLoader.getResourceXXX() to load the images, which will work out of a jar? Or do you use FileInputStream, file: URLs, or something similar, which won't?
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have no clue what either of those are...

i just said;




i thought when the jar compresses it, it stays with that exe. jar
for ever, like a copy of that .GIF file

am I wrong?

thanks,


Justin
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API documentation of the constructor of ImageIcon says:

public ImageIcon(String filename)

...

Parameters:
filename - a String specifying a filename or path


So it is looking for a file with the specified name. If you don't specify a directory (as you did), it will look for the file in the current directory. If you put your file inside a JAR, then it will not find the file.

Have a look at the API documentation for ImageIcon. It has another constructor that takes an URL. You could use that to load the image from a JAR file like this:
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URL url = MyClass.class.getResource("pic.GIF");

so this code will make the main class look for the pic inside
the jar file?

if so then thats what i need, however, what i dont need is
the jar looking for a file in a certain directory, what i need
is for the jar to run the same on different computers...

Thanks Again

Justin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic