This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • 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
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic