aspose file tools*
The moose likes Java in General and the fly likes jar wont load image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "jar wont load image" Watch "jar wont load image" New topic
Author

jar wont load image

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i reduced my problem to its simplest form

i have a jframe that displays an icon image

this image is inside a folder called img

when i run it from command line all is fine, but trouble comes with making the jars

yes i made two jars - i jared the img folder:

>jar cf img.jar img

the app jar:

>jar -cmf MANIFEST.MF T.jar *



what happens: when i move the jar away from its original folder (i.e. without the img folder next to it) and click on the jar file the image doesnt show up

what am i doing wrong?

the initial folder and the img jar were added to classpath....


java amateur
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19074
    
  40

Did you specify a classpath in your manifest? If you did, it will use that classpath, and not the environment variable classpath.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Henry Wong wrote:Did you specify a classpath in your manifest? If you did, it will use that classpath, and not the environment variable classpath.

Henry


the manifest for the main jar:
Manifest-Version: 1.0
Main-Class: Teste

the one for the images was self generated
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
after reading the sun java tutorials i changed my manifest to:

Manifest-Version: 1.0
Class-Path: img.jar
Main-Class: Teste

but with no results as well
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19074
    
  40

Question: in the orignal location. Does it work if the image.jar isn't there? Something tells me that you were using the images based on their file location, instead of the classpath location.

Henry
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Henry Wong wrote:Question: in the orignal location. Does it work if the image.jar isn't there? Something tells me that you were using the images based on their file location, instead of the classpath location.

Henry

yes!
i was just checking if there's something wrong with paths within the img jar



i tried this:

java -cp .;img.jar Teste

and indeed the image does not load too...



in the meanwhile i lost the link where i read (in sun java tuts too) about this "-" in order to make relative paths inside the jar like: "/img/myImage", but i cant find it

at this point as you can imagine i'm quite confused and i'd like to start over again from scratch: what do you recomend?

- deleting the environment varialble with classpath?

- looking for the "-" command to alter the making of the ing.jar?


thaks in advance and thanks for all the help
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Henry Wong wrote:Question: in the orignal location. Does it work if the image.jar isn't there? Something tells me that you were using the images based on their file location, instead of the classpath location.

Henry


i made both jars from the very same location
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20

How are you loading the images? Using Class.getResource or using ClassLoader.getResource?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
and i found the link

i tried both ways...

here's what i'm doing:
i move the prompt to the folder where my .java and my .class files and my folder img are

from here too i create both jars as i described above

but still the img.jar proves itself disposable , either when running the app or the main jar...
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Rob Prime wrote:How are you loading the images? Using Class.getResource or using ClassLoader.getResource?

you gave me the idea!:

and


the image loads when i run and loads too when i jar the class (even if i separate it from the img folder) - so, no need (so far) for the img.jar

its late here and i'll try the img.jar version tomorrow



thanks a lot, Robert!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jar wont load image