What is the MANIFEST.MF file inside a JAR, and how does Maven create it for you?
answer
- META-INF/MANIFEST.MF
- Name: value headers
- maven-jar-plugin at package phase
- <archive> config block
- Manifest-Version + Created-By defaults
basics
~10 sMANIFEST.MF lives in META-INF/ inside a JAR and holds metadata as key: value lines (like the entry-point class). The maven-jar-plugin generates it automatically when you build with packaging jar.
solid answer
~30 sEvery JAR contains a META-INF/MANIFEST.MF file: plain text, one "Name: value" header per line, that the JVM and tooling read for metadata. When your project uses <packaging>jar</packaging>, the maven-jar-plugin runs at the package phase and writes this file. By default it adds Manifest-Version, Created-By, and Build-Jdk-Spec. You can extend it via the plugin's <configuration><archive> block: <manifest> controls generated headers (mainClass, addClasspath, addDefaultImplementationEntries) and <manifestEntries> lets you add arbitrary custom headers. The manifest is what makes a JAR runnable (Main-Class), declares a classpath (Class-Path), or carries version info (Implementation-Version).
code
bash · 2 linesmvn package
unzip -p target/app.jar META-INF/MANIFEST.MFgo deeper
Know it lives in META-INF, is key:value text, and Maven writes it for jar packaging.
Know the <archive> config block with <manifest> vs <manifestEntries> and how to inspect the output.
Know which headers are auto-generated vs manual, and the package-phase binding of maven-jar-plugin.
Standardize manifest metadata (build provenance, version headers) across modules via a parent pom and shared plugin management.
## What a JAR and its manifest are A **JAR** (Java ARchive) is just a ZIP file with a `.jar` extension that bundles compiled `.class` files and resources. Inside, a special folder named `META-INF` holds metadata. The most important metadata file is **`META-INF/MANIFEST.MF`** — a plain-text file the Java runtime and build tools read. ## Manifest format The manifest is a list of **headers**, one per line, in the form `Name: value` (note the mandatory single space after the colon). Lines longer than 72 bytes are wrapped. A blank line separates the *main* section from optional *per-entry* sections. Example main section: ``` Manifest-Version: 1.0 Created-By: Apache Maven 3.9.6 Build-Jdk-Spec: 17 Main-Class: com.example.App ``` ## How Maven produces it When your `pom.xml` declares `<packaging>jar</packaging>` (the default), Maven binds the **maven-jar-plugin**'s `jar:jar` goal to the **package** phase. That plugin builds the archive and writes the manifest. You don't list the plugin explicitly unless you want to configure it. You customize the manifest through the plugin's `<configuration>` → `<archive>` element: - `<manifest>` — toggles *generated* headers: `<mainClass>`, `<addClasspath>`, `<addDefaultImplementationEntries>`, etc. - `<manifestEntries>` — free-form custom headers you type yourself. - `<manifestFile>` — point to a hand-written manifest to merge in. ## Worked pom snippet ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.example.App</mainClass> </manifest> <manifestEntries> <Built-By>ci-server</Built-By> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> ``` After `mvn package`, inspect it with `unzip -p target/app.jar META-INF/MANIFEST.MF`. ## Why it matters The manifest is how a JAR declares its **entry point** (`Main-Class`), an external **classpath** (`Class-Path`), **version/vendor** info (`Implementation-*`), and advanced features like **Multi-Release** JARs. Without it the JVM cannot `java -jar` your archive.
- Which Maven phase writes the manifest, and via which plugin/goal?The package phase, via the maven-jar-plugin's jar:jar goal, which is bound by default for jar packaging.
- Name two headers Maven adds to the manifest by default.Manifest-Version and Created-By (also Build-Jdk-Spec); none of the Implementation-* or Main-Class headers appear unless configured.
The manifest is like the label on a shipping box: it doesn't change the contents, but it tells the handler what's inside, who sent it, and where it should go (which class to run).
saying these in an interview costs you the question
- Saying the manifest stores your actual code or dependencies (it stores only metadata/headers)
- Thinking you must always declare maven-jar-plugin explicitly — it's bound by default for jar packaging
- Confusing META-INF/MANIFEST.MF with a properties file (colon-space format, not = )