The JAR Manifest File
You'll learn what the manifest file is, where it lives, and what metadata it can store inside a JAR.
What Is the Manifest File?
Every JAR file automatically contains a special metadata file called MANIFEST.MF, stored in the META-INF directory inside the JAR. Think of it as the "identity card" for your JAR—it describes what's inside, how to run it, and other important details about the packaged code.
When you create a JAR file, the jar command generates a basic manifest automatically. You can also provide your own custom manifest to add specific information.
Manifest Structure
The manifest file uses a simple text format with key-value pairs:
Manifest-Version: 1.0
Created-By: 17.0.2 (Oracle Corporation)
Each line follows the pattern Key: Value, and sections are separated by blank lines.
Common Manifest Attributes
Main-Class: Specifies which class contains the main method to run when you execute the JAR:
Main-Class: com.example.MyApplication
This allows users to run your JAR with java -jar myapp.jar instead of specifying the class name.
Class-Path: Lists external JAR files or directories your application needs:
Class-Path: lib/database.jar lib/utilities.jar
Version Information: Tracks implementation and specification versions:
Implementation-Version: 2.1.0
Implementation-Vendor: MyCompany
These attributes help tools and users identify what version of your code they're running.
Key Takeaway: The manifest file (META-INF/MANIFEST.MF) is the metadata descriptor for a JAR, storing crucial information like which class to run (Main-Class), external dependencies (Class-Path), and version details—making your JAR self-documenting and executable.