For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2006 > jar-file not using added files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author jar-file not using added files
Caj Zell

2006-08-18, 10:01 pm

I have the following problem:





I have a java-application that includes a few jpgs as background and


icons. I include them with the following code:





image = Toolkit.getDefaultToolkit().getImage("pic.JPG");


repaint();


and

URL url = getClass().getClassLoader().getResource("pic2.JPG");

JLabel rightImage = new JLabel( new ImageIcon(url));

This works fine when I run this application with java. Then I made a


jar-file out of it with the following command:
..../jdk1.5.0_01/bin/jar -cvmf myManifest.mf app.jar *.class pic.JPG


pic2.JPG

If I run this jar-file from that directory with

java -jar app.jar

everything goes well, but if I move it to another directory and run it


with the same command, it won't find the jpgs, even though I can see


them if I list the jar-files contents with



jar tf app.jar

Shouldn't it be possible to just run the tar-file and assume every file
is ready to use?

Andrew Thompson

2006-08-18, 10:01 pm

Caj Zell wrote:
> I have the following problem:
>
> I have a java-application that includes a few jpgs as background and

....
> image = Toolkit.getDefaultToolkit().getImage("pic.JPG");


Try this..
image = Toolkit.getDefaultToolkit().getImage("/pic.JPG");


HTH

Andrew T.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com