File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JNLP and Web Start and the fly likes Executable Jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "Executable Jar" Watch "Executable Jar" New topic
Author

Executable Jar

Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Hi,
I wanted to make my java proj into a executable jar file. This project includes severals images.jpg and a main.class. I used the command :
jar cmf manifest-file main.jar *.class *.jpg

I can launch the java appln by double click on the jar file, but the images does not display.

Anyone can tell me what I should do, inorder to display the images from the jar file?

Thank You
Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243
Hi,

Originally posted by Hydra Iris:

I can launch the java appln by double click on the jar file, but the images does not display.

Anyone can tell me what I should do, inorder to display the images from the jar file?


Can you show us the code for how you are trying to load up the images in your application? As a guess, sounds like you are trying to load them from a directory location, not from the jar file package structure via a classloader.

Cheers, Jared.


SCJP 1.4 91%, SCJP 1.5 88%, SCJD B&S
Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Show what code? This is my first time trying to make a excutable jar file from : http://www.cs.princeton.edu/introcs/85application/jar/jar.html

I have a main.class file and dinmaster.jpg. So to make the executable jar file I created the manifest.txt file containing
Manifest-Version: 1.0
Main-Class: main

I typed the cmd >jar cmf manifest.txt myproj.jar main.class dinmaster.jpg

So, I expect when i double click myproj.jar, the project launch. Yes it did, but then there are no images display at all. My image is set to local path sth like this :
dinmasterLbl=new JLabel();
dinmasterLbl.setIcon(new ImageIcon("dinmaster.jpg"));

I hope u can understand my questions.........thanks
Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243
Originally posted by Hydra Iris:

Show what code?
dinmasterLbl=new JLabel();
dinmasterLbl.setIcon(new ImageIcon("dinmaster.jpg"));


This is what I wanted. You can't do this when the image is stored in the jar file itself.

This works when the file is out in the file system somewhere, but not in the jar file. This is expecting to file the .jpg file in the current home directory of the application jar file (where-ever you double click the jar file from).

You need to do this instead to load it from the application jar file package structure:



Obviously reference the image from the correct place within your jar file. You will need to do this where ever you are trying to load up images.

Cheers, Jared.
Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Yes is working now. All images can be displayed as expected. I'm so happy......Thank You )
debashis paul
Greenhorn

Joined: Jul 18, 2006
Posts: 2
Actually there is the prolem that where are you keeping the images,when u are making the executable jar file binding all files and folder like manifest,images,class files etc. You must have to keep the image files in that directory where you are keepng your main project folder otherwise u can give the full path of the images where actually u are keeping the images. I think now you will be able to see the images when u will execute the jar file.
Hydra Iris
Greenhorn

Joined: Jun 21, 2006
Posts: 13
Noted. Thanks
 
jQuery in Action, 2nd edition
 
subject: Executable Jar