• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Executable Jar

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Hydra Iris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes is working now. All images can be displayed as expected. I'm so happy......Thank You )
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Noted. Thanks
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic