Image lost within JAR file

90 pts.
Tags:
Image and media files
JAR files
Java development
Hello, I am developing a Java Application which I would like to Convert into a JAR file. Within the main project directory I have an image which is used in the application, but when I convert the project to JAR form the application cannot find the file. My Filesystem: +Project      -src      -bin      -image.jpg When I build the JAR, the image is placed in the directory with the JAR, not inside it, although I've tried placing the file inside the JAR file as well. Inside my Java code the image is simply referenced as "image.jpg". Does anyone know how to fix this exception?

Software/Hardware used:
Java, JAR, Ant Build

Answer Wiki

Thanks. We'll let you know when a new response is added.

I solved the problem. If I move the image into the src file and rebuild, then reference it as a resource, much like you suggested, the program finds the file perfectly. The file is reproduced in my bin folder, which is the focus of the Ant build. Thus, image is put in JAR, Program functions correctly, and everyone is happy. Thanks for the help!

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    I think you need to use getResource to read the image file. Take a look at this article: Accessing a resource within a .jar Does it help ? If not, please post some code, and the exception you are getting.
    69,510 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following