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

PartIn demo.jarWhat it is
Local entries55 × (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 directory3,525 bytes at 32,228A 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 record22 bytes at 35,753The 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.

OffsetBytesFieldValue
3575322 bytesend of central directory
3575350 4b 05 06signaturePK 05 06
3575700 00disk_number0
3575900 00cd_start_disk0
3576137 00entries_on_disk55
3576337 00total_entries55
35765c5 0d 00 00cd_size3525
35769e4 7d 00 00cd_offset32228
3577300 00comment_length0

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.

OffsetBytesFieldValue
3349057 bytesentry 20Hello.class
3349050 4b 01 02signaturePK 01 02
3349414 00version_made_by2.0 on MS-DOS / Windows
3349614 00version_needed2.0
3349808 08flags0x0808
3350008 00method8 (deflated)
3350200 00mod_time0
3350421 5cmod_date2026-01-01 00:00:00
335063c 0e 43 4bcrc320x4b430e3c
33510df 01 00 00compressed_size479
3351425 03 00 00uncompressed_size805
335180b 00name_length11
3352000 00extra_length0
3352200 00comment_length0
3352400 00disk_number_start0
3352600 00internal_attributes0
3352800 00 00 00external_attributes0x00000000
3353213 29 00 00local_header_offset10515
3353648 65 6c 6c 6f 2e 63 6c 61 73 73name"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.

OffsetBytesFieldValue
10515536 byteslocal entry Hello.class805 bytes, deflated
1051541 byteslocal file header
1051550 4b 03 04signaturePK 03 04
1051914 00version_needed2.0
1052108 08flags0x0808
1052308 00method8 (deflated)
1052500 00mod_time0
1052721 5cmod_date2026-01-01 00:00:00
1052900 00 00 00crc320
1053300 00 00 00compressed_size0
1053700 00 00 00uncompressed_size0
105410b 00name_length11
1054300 00extra_length0
1054548 65 6c 6c 6f 2e 63 6c 61 73 73name"Hello.class"
10556479 bytesfile data
105566d 52 cb 6e d3 40 14 3d 13 c7 99 c4 …compressed bytes
1103516 bytesdata descriptor
1103550 4b 07 08signaturePK 07 08
110393c 0e 43 4bcrc321262685756
11043df 01 00 00compressed_size479
1104725 03 00 00uncompressed_size805

Open demo.jar in the viewer

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-VersionThe manifest format version, always 1.0. Without it the JDK ignores the manifest.
Created-ByThe tool that wrote the manifest, usually the JDK version and vendor (from the jar tool) or the build plugin.
Built-ByThe user name of whoever ran the build: often a CI account, sometimes a person.
Build-Jdk-SpecThe Java version Maven ran on when it built the JAR (not necessarily the classes' target).
Build-JdkThe exact JDK version the build ran on.
Main-ClassThe class java -jar runs: it must have public static void main(String[]).
Class-PathOther 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-ClassA Java agent started before main, when this JAR is run with java -jar.
Premain-ClassMakes this JAR a Java agent: the class whose premain method runs before the application's main, with -javaagent.
Agent-ClassThe class whose agentmain runs when this agent is loaded into a JVM that is already running.
Can-Redefine-ClassesWhether the agent may redefine classes that are already loaded.
Can-Retransform-ClassesWhether the agent may retransform classes that are already loaded.
Boot-Class-PathJARs the agent wants on the bootstrap class path.
Multi-Releasetrue 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-NameThe 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-OpensPackages to open to all unnamed modules (deep reflection), as with --add-opens, when run with java -jar.
Add-ExportsPackages to export to all unnamed modules, as with --add-exports, when run with java -jar.
Enable-Native-AccessALL-UNNAMED lets code in this JAR call restricted native methods (the FFM API, JNI) without a warning, when run with java -jar.
Sealedtrue seals the packages in this JAR: all their classes must come from this JAR.
Implementation-TitleThe name of the implementation, readable at run time through Package.getImplementationTitle().
Implementation-VersionThe version of the implementation, readable through Package.getImplementationVersion().
Implementation-VendorWho made the implementation.
Implementation-Vendor-IdThe vendor's ID, often a Maven group ID.
Specification-TitleThe specification this JAR implements.
Specification-VersionThe version of the specification it implements.
Specification-VendorWho owns the specification.
Bundle-SymbolicNameOSGi: the bundle's unique name. This JAR is also an OSGi bundle.
Bundle-VersionOSGi: the bundle's version.
Export-PackageOSGi: the packages other bundles may import.
Import-PackageOSGi: the packages this bundle needs.
Start-ClassSpring 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-VersionSpring Boot: the version that built this executable JAR.
Spring-Boot-ClassesSpring Boot: where the application's own classes are (BOOT-INF/classes/).
Spring-Boot-LibSpring Boot: where the dependency JARs are, stored uncompressed so they can be read in place.
Spring-Boot-Classpath-IndexSpring Boot: a file listing the dependency JARs in class path order.
Spring-Boot-Layers-IndexSpring Boot: a file grouping the contents into layers for container images.
SHA-256-DigestSigned JARs: the entry's SHA-256 digest, checked against the signature file.
SHA1-DigestSigned JARs: the entry's SHA-1 digest (older signers).
X-Compile-Source-JDKSome builds record the javac source level here.
X-Compile-Target-JDKSome 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 of Hello there.
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.xml and a pom.properties with 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.