Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Jar file problem

  Asked By: Bertha    Date: Apr 11    Category: Java    Views: 742
  

I am trying to learn about jar files.
I have an application in a folder, with a number of text and image
files (all in the one directory).

I created a jar file with all the files in that directory, and
successfully launched the program with

java -jar Project.jar

But....when I take all other files except the jar file out of that
folder, it won't run and I get an "uncaught exception fetching image"
error. I thought the point was that a jar file wrapped everything up
into itself, and so once that was created, you didn't need to worry
about other files and could just export that on its own as your
application.

What am I doing wrong here?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Alfonsine Miller     Answered On: Apr 11

Sounds like the image isn't included in the jar  file.

 
Answer #2    Answered By: Fedde Bakker     Answered On: Apr 11

I guess that's my question though. I thought
the image files  were bundled up *IN* the jar  file?....so does that
mean that if you send out an application, you always have to have the
image and text  files separately in that folder  too?

 
Answer #3    Answered By: Taylor White     Answered On: Apr 11

No. Just make sure you get the correct URL of the resource files.
Like:

URL url = java.net.URLClassLoader.getSystemResource( "image.jpg" );
Image image = java.awt.Toolkit.getDefaultToolkit().getImage( url );

Instead of:

Image image = java.awt.Toolkit.getDefaultToolkit().getImage
( "image.jpg" );

 
Didn't find what you were looking for? Find more on Jar file problem Or get search suggestion and latest updates.




Tagged: