Java Tools Tutorials - Herong's Tutorial Examples - v6.23, by Herong Yang
Adding META-INF/MANIFEST.MF to JAR Files
This section provides a tutorial example on how to create and add manifest files manually to JAR files.
There are two ways to add "manifest" to a JAR file.
1. Adding "manifest" through "jar" command line. Store all your manifest attributes in a file. And specify this file in the "jar" command line with the "--manifest=FILE" option. The old formats of the "--manifest" option are "-m" and "m".
For example, I created my own manifest file called manifest.txt with one attribute in it:
Remember to press the <Enter> key at the end of the attribute list. This will insert a blank line to terminate the attribute list.
Here is how I added my manifest to a JAR file with the "--manifest" option:
herong> jar --create --verbose --file hello.jar \ --manifest=manifest.txt Hello.class added manifest adding: Hello.class(in = 416) (out= 285)(deflated 31%)
To verify if the manifest file was added correctly or not, I extracted all files out of the JAR file and checked the META-INF/MANIFEST.MF file:
herong> jar --extract --verbose --file hello.jar created: META-INF/ inflated: META-INF/MANIFEST.MF inflated: Hello.class herong> type META-INF\MANIFEST.MF Manifest-Version: 1.0 Main-Class: Hello Created-By: 10.0.1 (Oracle Corporation)
As you can see, the "jar --create" command copied the attribute from my manifest file into the auto-generated MANIFEST.MF file.
2. Adding "manifest" through META-INF/MANIFEST.MF file. Create META-INF/MANIFEST.MF as a text file. Enter all your manifest attributes in this file. And include META-INF/MANIFEST.MF as an input file to "jar --create" command.
For example, I created my own META-INF/MANIFEST.MF with a text editor as:
Manifest-Version: 3.3 Created-By: Herong Yang Main-Class: Hello
Here is how I added my manifest to a JAR file by providing the META-INF as an input entry:
herong> jar --create --verbose --file tutu.jar --no-manifest \ Hello.class META-INF adding: Hello.class(in = 416) (out= 285)(deflated 31%) adding: META-INF/(in = 0) (out= 0)(stored 0%) adding: META-INF/MANIFEST.MF(in = 69) (out= 69)(deflated 0%) herong> jar --list --verbose --file tutu.jar 416 ... 2018 Hello.class 0 ... 2018 META-INF/ 69 ... 2018 META-INF/MANIFEST.MF
Table of Contents