• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

jar wont load image

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you loading the images? Using Class.getResource or using ClassLoader.getResource?
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
bacon. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic