• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jar file help please

 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic