Reference
The JAR file format
A JAR is a ZIP file with a manifest. Here is a real one, demo.jar (35,775 bytes, 55 entries), decoded from the first byte to the last.
Everything that makes a JAR a JAR is a convention inside an ordinary ZIP archive: a text file at META-INF/MANIFEST.MF, classes stored under their package paths, and a few other files in META-INF/. Any ZIP tool can open one, and jar can open any ZIP. So reading a JAR means reading a ZIP, which is read backwards.
The layout
| Part | In demo.jar | What it is |
|---|---|---|
| Local entries | 55 × (header + data) | For each file, a local header (signature PK\3\4, name, sizes, CRC) and then its compressed bytes. Enough to read the archive front to back, as a stream. |
| Central directory | 3,525 bytes at 32,228 | A record per entry (PK\1\2) repeating its name and sizes and adding where its local header is. This is the index readers use. |
| End record | 22 bytes at 35,753 | The last thing in the file (PK\5\6): how many entries there are and where the central directory starts. A reader finds it by searching back from the end. |
Because readers start at the end, anything can be put in front of a JAR: a shell script that runs java -jar "$0" makes it a self-running executable, and the JVM still opens it. It is also why a JAR cut short loses its index and cannot be opened at all, even though most of its entries are intact.
1. The end record
Readers look for the signature 50 4b 05 06 in the last 22 bytes (plus up to 64 KB of comment). Its last two numbers say where the central directory is.
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 35753 | 22 bytes | end of central directory | |
| 35753 | 50 4b 05 06 | signature | PK 05 06 |
| 35757 | 00 00 | disk_number | 0 |
| 35759 | 00 00 | cd_start_disk | 0 |
| 35761 | 37 00 | entries_on_disk | 55 |
| 35763 | 37 00 | total_entries | 55 |
| 35765 | c5 0d 00 00 | cd_size | 3525 |
| 35769 | e4 7d 00 00 | cd_offset | 32228 |
| 35773 | 00 00 | comment_length | 0 |
2. A central directory record
The record for Hello.class. Readers list the archive from these records alone; the local_header_offset says where to find the data.
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 33490 | 57 bytes | entry 20 | Hello.class |
| 33490 | 50 4b 01 02 | signature | PK 01 02 |
| 33494 | 14 00 | version_made_by | 2.0 on MS-DOS / Windows |
| 33496 | 14 00 | version_needed | 2.0 |
| 33498 | 08 08 | flags | 0x0808 |
| 33500 | 08 00 | method | 8 (deflated) |
| 33502 | 00 00 | mod_time | 0 |
| 33504 | 21 5c | mod_date | 2026-01-01 00:00:00 |
| 33506 | 3c 0e 43 4b | crc32 | 0x4b430e3c |
| 33510 | df 01 00 00 | compressed_size | 479 |
| 33514 | 25 03 00 00 | uncompressed_size | 805 |
| 33518 | 0b 00 | name_length | 11 |
| 33520 | 00 00 | extra_length | 0 |
| 33522 | 00 00 | comment_length | 0 |
| 33524 | 00 00 | disk_number_start | 0 |
| 33526 | 00 00 | internal_attributes | 0 |
| 33528 | 00 00 00 00 | external_attributes | 0x00000000 |
| 33532 | 13 29 00 00 | local_header_offset | 10515 |
| 33536 | 48 65 6c 6c 6f 2e 63 6c 61 73 73 | name | "Hello.class" |
3. The local header and the data
At that offset: the local header, repeating most of the central record, and then 479 bytes of deflated data that inflate to the 805-byte class file. The jar tool writes entries as a stream, so it sets flag bit 3 and puts the CRC and sizes in a data descriptor after the data; the central directory has them too.
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 10515 | 536 bytes | local entry Hello.class | 805 bytes, deflated |
| 10515 | 41 bytes | local file header | |
| 10515 | 50 4b 03 04 | signature | PK 03 04 |
| 10519 | 14 00 | version_needed | 2.0 |
| 10521 | 08 08 | flags | 0x0808 |
| 10523 | 08 00 | method | 8 (deflated) |
| 10525 | 00 00 | mod_time | 0 |
| 10527 | 21 5c | mod_date | 2026-01-01 00:00:00 |
| 10529 | 00 00 00 00 | crc32 | 0 |
| 10533 | 00 00 00 00 | compressed_size | 0 |
| 10537 | 00 00 00 00 | uncompressed_size | 0 |
| 10541 | 0b 00 | name_length | 11 |
| 10543 | 00 00 | extra_length | 0 |
| 10545 | 48 65 6c 6c 6f 2e 63 6c 61 73 73 | name | "Hello.class" |
| 10556 | 479 bytes | file data | |
| 10556 | 6d 52 cb 6e d3 40 14 3d 13 c7 99 c4 … | compressed bytes | |
| 11035 | 16 bytes | data descriptor | |
| 11035 | 50 4b 07 08 | signature | PK 07 08 |
| 11039 | 3c 0e 43 4b | crc32 | 1262685756 |
| 11043 | df 01 00 00 | compressed_size | 479 |
| 11047 | 25 03 00 00 | uncompressed_size | 805 |
The manifest
META-INF/MANIFEST.MF is text: Name: value lines in UTF-8, each at most 72 bytes, with longer values continued on lines that begin with a single space. A blank line ends the main section; any further sections start with Name: and apply to one entry (a signed JAR has one per file, holding its digest). demo.jar's:
Manifest-Version: 1.0 Main-Class: Hello Multi-Release: true Automatic-Module-Name: net.uresk.demo Implementation-Title: Hexplained demo Implementation-Version: 1.0.0 Created-By: 25.0.5 (Eclipse Adoptium)
7 attributes in the main section. These are the ones the JDK and common tools understand:
Manifest-Version | The manifest format version, always 1.0. Without it the JDK ignores the manifest. |
|---|---|
Created-By | The tool that wrote the manifest, usually the JDK version and vendor (from the jar tool) or the build plugin. |
Built-By | The user name of whoever ran the build: often a CI account, sometimes a person. |
Build-Jdk-Spec | The Java version Maven ran on when it built the JAR (not necessarily the classes' target). |
Build-Jdk | The exact JDK version the build ran on. |
Main-Class | The class java -jar runs: it must have public static void main(String[]). |
Class-Path | Other JARs to load, as relative URLs separated by spaces, resolved against this JAR's location. Only used with java -jar or when the JAR is on the class path. |
Launcher-Agent-Class | A Java agent started before main, when this JAR is run with java -jar. |
Premain-Class | Makes this JAR a Java agent: the class whose premain method runs before the application's main, with -javaagent. |
Agent-Class | The class whose agentmain runs when this agent is loaded into a JVM that is already running. |
Can-Redefine-Classes | Whether the agent may redefine classes that are already loaded. |
Can-Retransform-Classes | Whether the agent may retransform classes that are already loaded. |
Boot-Class-Path | JARs the agent wants on the bootstrap class path. |
Multi-Release | true makes this a multi-release JAR: classes under META-INF/versions/N/ replace the ones at the root on Java N and later. |
Automatic-Module-Name | The module name this JAR gets when it is put on the module path without a module-info.class, instead of a name guessed from the file name. |
Add-Opens | Packages to open to all unnamed modules (deep reflection), as with --add-opens, when run with java -jar. |
Add-Exports | Packages to export to all unnamed modules, as with --add-exports, when run with java -jar. |
Enable-Native-Access | ALL-UNNAMED lets code in this JAR call restricted native methods (the FFM API, JNI) without a warning, when run with java -jar. |
Sealed | true seals the packages in this JAR: all their classes must come from this JAR. |
Implementation-Title | The name of the implementation, readable at run time through Package.getImplementationTitle(). |
Implementation-Version | The version of the implementation, readable through Package.getImplementationVersion(). |
Implementation-Vendor | Who made the implementation. |
Implementation-Vendor-Id | The vendor's ID, often a Maven group ID. |
Specification-Title | The specification this JAR implements. |
Specification-Version | The version of the specification it implements. |
Specification-Vendor | Who owns the specification. |
Bundle-SymbolicName | OSGi: the bundle's unique name. This JAR is also an OSGi bundle. |
Bundle-Version | OSGi: the bundle's version. |
Export-Package | OSGi: the packages other bundles may import. |
Import-Package | OSGi: the packages this bundle needs. |
Start-Class | Spring Boot: the application's real main class. Main-Class is Spring Boot's launcher, which sets up the nested JARs and then calls this. |
Spring-Boot-Version | Spring Boot: the version that built this executable JAR. |
Spring-Boot-Classes | Spring Boot: where the application's own classes are (BOOT-INF/classes/). |
Spring-Boot-Lib | Spring Boot: where the dependency JARs are, stored uncompressed so they can be read in place. |
Spring-Boot-Classpath-Index | Spring Boot: a file listing the dependency JARs in class path order. |
Spring-Boot-Layers-Index | Spring Boot: a file grouping the contents into layers for container images. |
SHA-256-Digest | Signed JARs: the entry's SHA-256 digest, checked against the signature file. |
SHA1-Digest | Signed JARs: the entry's SHA-1 digest (older signers). |
X-Compile-Source-JDK | Some builds record the javac source level here. |
X-Compile-Target-JDK | Some builds record the javac target level here. |
What else lives in META-INF
versions/N/- Multi-release JARs: classes that replace the root ones on Java N and later, when the manifest says
Multi-Release: true. demo.jar has a Java 21 build ofHellothere. services/- ServiceLoader registrations: a file named after an interface, listing implementing classes.
*.SF,*.RSA,*.EC- A signature: the .SF file holds digests of the manifest's sections, the block file signs the .SF. The JVM checks each entry as it loads it.
maven/- Maven's copy of the project's
pom.xmland apom.propertieswith its group, artifact and version. module-info.class- Not in META-INF but at the root (or under
versions/N/): makes the JAR an explicit module.
Specifications: the JAR File Specification (Java SE 25) and PKWARE's APPNOTE.TXT for ZIP. demo.jar holds 51,795 bytes of files in 35,775 bytes.