• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jar wont load image

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Henry Wong
author
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you specify a classpath in your manifest? If you did, it will use that classpath, and not the environment variable classpath.

Henry
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you loading the images? Using Class.getResource or using ClassLoader.getResource?
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic