File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes jar file help please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "jar file help please" Watch "jar file help please" New topic
Author

jar file help please

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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 ]

You down with OOP? Yeah you know me!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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?


[Jess in Action][AskingGoodQuestions]
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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

Joined: Aug 16, 2005
Posts: 13872
    
  10

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jar file help please
 
Similar Threads
jar size
how to create JAR(executable) in Windows...
Caching of Images used in Applet
packaging the Java Swing application
getResource error when starting application in a jar file