Introduction

The jar command can customize the contents of the manifest file.

option m sets your own manifest file.

The jar command will read the name-value pairs from the specified manifest file and add them to the MANIFEST.MF file.

Suppose you have a file named manifest.txt with one attribute entry in it.

Add a new line at the end of the file. The file's contents are as follows:

Main-Class: com.book2s.intro.Welcome

To add the Main-Class attribute value from manifest.txt file in a new test.jar file by including all class files in the current working directory, use the following command:

jar cfm test.jar manifest.txt *.class

When setting the option m, you must specify the manifest file name.

The order in which you specify the new JAR file name and the manifest file name must match the order of options m and f.

For example, you can change the above command by specifying the f and m options in a different order as follows:

jar cmf manifest.txt test.jar *.class

This command will add a manifest file with the following contents to the test.jar file:

Manifest-Version: 1.0
Created-By: 1.8.0_20-ea (Oracle Corporation)
Main-Class: com.book2s.intro.Welcome

Related Topic