This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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

How to make jar file executeable ?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hallo expert people,
i have made a jar file with the following command : jar cf backup.jar backup_pro.class backup_pro$zip.class ... and if i run with the following command : java -jar backup.jar , it will work but if i double click there is an error "Could not find the main class. Program will exit!". Have any one experience how to make jar file executeable with double click. I have download many jar files from internet and they are working with double click and "java -jar jarfiles.jar" command. Any Help will be appreciated.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure,

You should write your own Manifest.mf file and force the Java Jar utility to use it with the -m command. Your Manifest.mf file should have an entry called "Main-Class" that points to the class in your application that has the



method. An example Manifest.mf file would look like:

 
benny rusli
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My MANIFEST.MF seems right as yours, here is the content of my Manifest file :

where backup_pro is the main class, the jar file that i create "backup.jar" work with the following command "java -jar backup.jar" but not with double click. What do you mean with -m ? can you give a complete command ? thank you very much.
 
Yevgeniy Treyvus
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The -m command simply tells the Jar utility to package the Manifest.mf file you wrote within the Jar. An example command would look like:

jar cmf Sample.mf Sample.jar Sample.class Turtle.class Sample.java Turtle.java images

You can find a more complete exlanation in this tutorial:

http://www.cs.princeton.edu/introcs/85application/jar/jar.html

Make sure your Manifest.mf file is in the META-INF folder. An example structure would look like:

META-INF/
META-INF/MANIFEST.MF
Sample.class
Turtle.class
Sample.java
Turtle.java
images/
images/image1.gif
images/image2.gif
images/image3.gif

You can use something like Winzip to look at the contents of your Jar file. Make sure all needed .class files are indeed there.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The manifest has to be correct, if you call 'java -jar xy.jar' too, shouldn't it?
So it shouldn't be the reason.

Suspicious, suspicious...

You're sure about the errormessage?
 
He baked a muffin that stole my car! And this tiny ad:
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