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:

Main-Class: Hello

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: Hello.class

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

Note that:

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 java - The Java Program Launcher

jar - The JAR File Tool

 JAR - Java Archive File Format

 jar - JAR File Tool Command and Options

 "jar --create" - Creating New JAR File

 "jar --list" - Listing Files in JAR File

 "jar --extract" - Extracting Files from JAR File

 Managing JAR Files with WinZIP



 "jar -C" - Changing Input Directory

 Using JAR Files in Java Class Paths

 "jar --update" - Updating Class Files in JAR

 "jar --main-class" - Making JAR File Executable

 Creating Module JAR File

 "jar --module-version" - Updating Module Version in JAR

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 jpackage - Binary Package Builder

 javadoc - The Java Document Generator

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 jrunscript - Script Code Shell

 Miscellaneous Tools

 native2ascii - Native-to-ASCII Encoding Converter

 JAB (Java Access Bridge) for Windows

 Archived Tutorials


 Full Version in PDF/EPUB