Java Tools Tutorials - Herong's Tutorial Notes - Version 5.31, by Dr. Herong Yang
Adding META-INF/MANIFEST.MF to JAR Files
This section provides a tutorial example on how to add manifest files 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 "m" option:
jar c[v0]mf manifest jarfile inputfiles
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. This will insert a new line character (\n) to terminate the attribute.
Here is how I added my manifest to a JAR file with the "m" option:
C:\herong>jar cvmf manifest.txt hello.jar Hello.class added manifest adding: Hello.class(in = 416) (out= 285)(deflated 31%) C:\herong>jar xvf hello.jar created: META-INF/ extracted: META-INF/MANIFEST.MF extracted: Hello.class C:\herong>type META-INF\MANIFEST.MF Manifest-Version: 1.0 Created-By: 1.8.0 (Oracle Corporation) Main-Class: Hello
As you can see that "jar" command copied the attribute from my manifest file to the end of 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 file.
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 with the "M" option:
C:\herong>jar cvMf tutu.jar 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 = 19) (out= 21)(deflated -10%) C:\herong>jar tf tutu.jar Hello.class META-INF/ META-INF/MANIFEST.MF
Last update: 2015.
Table of Contents