If a jar file contains an application’s main class, you can make the jar executable. This is a convenience for your users, because with an executable jar they don’t have to remember the name of the main class. To run an executable jar file, you just use the -jar option and name the file on the java command line, like this:
java -jar the_executable_archive.jar
To make an executable jar, first create a manifest that tells which class file is the main class.
To do this, create a text file that contains a line like the following:
Main-Class: x.y.MyMainClass
Note that you specify the class name, not the class filename, so there’s no .class suffix. Be to specify the entire class name, including package prefixes (x.y. in this example). The text can have any name at all. It is not inserted into the jar file. Instead, the jar program reads and copies its information into the manifest file, which the jar program creates.
Now build your jar file, using the -m option to tell jar which file to look in for manifest For if your Main-Class line is in a file called manny.txt, your command would be:
jar -cvfm my_arch.jar manny.txt *.class
The jar program reads the main class declaration in manny.txt and builds a manifest inside the main class declaration and a bit of extra information. Inside the jar a META-INF is created, and in META-INF is a plain-text file called MANIFEST.MF.
Here’s what MANIFEST.MF looks like for our example:
Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)
Main-Class: MyMainClass
Ease of use is an important part of software quality. A little familiarity with the jar program
increase the ease of use of your project.
Thanks to "Complete Java® 2 Certification: Study Guide, " Written by "Philip Heller,Simon Roberts"