What is the META-INF folder for in Java?
Codemia Knowledge Hub ·
META-INF is a reserved folder at the root of Java archives (JAR, WAR, EAR) that holds metadata and configuration describing how the archive behaves at build time, runtime and deployment. The JVM and application servers read it automatically, so its contents decide which class runs, how services are discovered and whether the archive has been tampered with.
If you have wondered why an executable JAR launches the right main class, or how Spring discovers beans without explicit registration, the answer is almost always a file in META-INF.
MANIFEST.MF
MANIFEST.MF is the most important file in META-INF, and standard tooling includes one in every JAR. It is a plain-text key-value file the JVM reads before doing anything else with the archive.
A minimal manifest for an executable JAR:
| Attribute | Purpose |
Main-Class | Entry point when running java -jar |
Class-Path | Additional JARs to include on the classpath |
Implementation-Version | Version string for the library or application |
Specification-Version | API contract version for compatibility checks |
Sealed | When set on a package, forces all classes in that package to come from this JAR |
Named sections define per-package attributes:
This seals the com.example.api package so other JARs cannot contribute classes to it at runtime, which prevents classpath conflicts and split-package issues.
Signature files for signed JARs
Signing a JAR adds files to META-INF:
The .SF file holds digests of each section of MANIFEST.MF. The .RSA (or .DSA or .EC) file holds the cryptographic signature and the signer's certificate chain. Together they let the JVM verify that nothing in the JAR changed after signing.
If any class file was altered, verification fails. This underpins Java WebStart security, applet trust decisions and enterprise deployment policies.
META-INF/services/ and ServiceLoader
META-INF/services/ drives Java's ServiceLoader, which supports pluggable architectures without compile-time coupling. Each file is named after a fully qualified interface or abstract class and lists the concrete implementations:
File contents:
The application discovers the implementations at runtime:
The JDK uses this pattern for JDBC drivers, XML parsers and cryptographic providers, and SLF4J uses it to discover logging backends.
Framework configuration files
Many frameworks keep their own configuration in META-INF:
| File | Framework | Purpose |
persistence.xml | JPA (Hibernate, EclipseLink) | Defines persistence units, data sources, and entity mappings |
beans.xml | CDI (Java EE / Jakarta EE) | Enables CDI bean discovery in the archive |
spring.factories | Spring Boot (pre-3.0) | Lists auto-configuration classes for component scanning |
spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports | Spring Boot 3.0+ | Replacement for spring.factories |
web-fragment.xml | Servlet 3.0+ | Declares servlets, filters, and listeners for modular web apps |
INDEX.LIST | JDK | Speeds up class loading by indexing package-to-JAR mappings |
A typical JPA persistence.xml:
META-INF in WAR and EAR archives
In a WAR, META-INF sits at the archive root and web resources go under WEB-INF. In an EAR, META-INF holds application.xml, which declares the packaged modules (WARs, EJB JARs).
META-INF is always at the archive root; different containers look for different files inside it.
META-INF mistakes that break discovery
persistence.xmlin the project root instead ofMETA-INF. JPA will not find it and either fails silently or throws an opaque error about missing persistence units.- Confusing
META-INFwithWEB-INF. They have different visibility rules:META-INFfiles are reachable viaClassLoader.getResource(), whileWEB-INFcontents are reached through theServletContext. - Naming services files after the implementation. Files in
META-INF/services/must be named with the fully qualified interface name. Reversed,ServiceLoaderfinds nothing. - No trailing newline in a hand-edited
MANIFEST.MF. The specification requires one, and some JVM implementations silently ignore the last entry without it. - Expecting eager loading.
ServiceLoaderinstantiates implementations lazily during iteration, which can hide startup errors until the service is first used.
Related reading
- What's the reason I can't create generic array types in Java?
- What's the syntax for mod in Java?
- What's wrong with overridable method calls in constructors?
- What's wrong with using to compare floats in Java?
- When and how should I use a ThreadLocal variable?
- When and why do we need ApplicationRunner and Runner interface?
- When and why JPA entities should implement the Serializable interface?
- When do I need to use AtomicBoolean in Java?
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.