Running a Program from a JAR File


java jar Scorebook.jar



Using the java command-line executable, you can execute a Java application that is packaged in a JAR file. To do this, you use the jar switch when running the java command. You must also specify the name of the JAR file that contains the application you want to execute.

You must specify the class containing the main() method that you want to execute in a manifest file. For example, to execute the com.timothyfisher.Scorebook class, you would use a manifest file with the following contents:

Manifest-Version: 1.2 Main-Class: com.timothyfisher.Scorebook Created-By: 1.4 (Sun Microsystems Inc.)


The manifest file is placed in the JAR file along with your classes.

This functionality allows Java developers to be able to distribute an application in a single JAR file and include a script file such as a Windows BAT file, or a UNIX shell script that can be used to launch the application using syntax similar to what is shown in this phrase.




JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net