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 ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.