Customizing the JAR Manifest
The JAR manifest file provides a way to store metadata about the contents of the JAR file. This metadata can be used to customize the behavior of the JAR file and the way it is executed. In this section, we'll explore some of the common manifest entries that you can use to customize your JAR files.
Common Manifest Entries
Here are some of the most commonly used manifest entries:
Entry |
Description |
Main-Class |
Specifies the fully qualified name of the main class that should be executed when the JAR file is run. |
Class-Path |
Specifies a list of JAR files or other resources that should be added to the classpath when the JAR file is executed. |
Created-By |
Specifies the name and version of the tool used to create the JAR file. |
Sealed |
Specifies whether the JAR file is sealed, which means that its contents cannot be modified. |
Implementation-Title , Implementation-Version , Implementation-Vendor |
Provide information about the implementation of the JAR file. |
Specification-Title , Specification-Version , Specification-Vendor |
Provide information about the specification that the JAR file implements. |
Customizing the Manifest
To customize the manifest file, you can create a text file with the desired entries and then use the jar
command to package the JAR file with the custom manifest.
For example, to create a JAR file with a custom manifest, you can use the following command:
jar cvfm my-app.jar manifest.mf -C bin/ .
Here, manifest.mf
is the name of the file containing the custom manifest entries.
You can also use the jar
command to update an existing JAR file with a new manifest:
jar ufm existing-app.jar new-manifest.mf
This command updates the manifest of the existing-app.jar
file with the entries in the new-manifest.mf
file.
By customizing the JAR manifest, you can provide additional information about your Java application and control how it is executed.