META-INF
Programming
Software Development
Java
Application Packaging

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:

plaintext
Manifest-Version: 1.0
Main-Class: com.example.App
Class-Path: lib/commons-lang3.jar lib/guava.jar
AttributePurpose
Main-ClassEntry point when running java -jar
Class-PathAdditional JARs to include on the classpath
Implementation-VersionVersion string for the library or application
Specification-VersionAPI contract version for compatibility checks
SealedWhen set on a package, forces all classes in that package to come from this JAR

Named sections define per-package attributes:

plaintext
1Manifest-Version: 1.0
2
3Name: com/example/api/
4Sealed: true
5Specification-Version: 2.0

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:

plaintext
1META-INF/
2  MANIFEST.MF
3  MYKEY.SF        # signature file (hashes of manifest entries)
4  MYKEY.RSA       # PKCS7 signature block (certificate + encrypted digest)

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.

bash
jarsigner -verify -verbose myapp.jar

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:

plaintext
META-INF/services/com.example.spi.PaymentProcessor

File contents:

plaintext
com.example.stripe.StripeProcessor
com.example.paypal.PayPalProcessor

The application discovers the implementations at runtime:

java
1import java.util.ServiceLoader;
2
3public class PaymentRegistry {
4    public static void main(String[] args) {
5        ServiceLoader<PaymentProcessor> loader =
6            ServiceLoader.load(PaymentProcessor.class);
7
8        for (PaymentProcessor processor : loader) {
9            System.out.println("Found: " + processor.getClass().getName());
10        }
11    }
12}

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:

FileFrameworkPurpose
persistence.xmlJPA (Hibernate, EclipseLink)Defines persistence units, data sources, and entity mappings
beans.xmlCDI (Java EE / Jakarta EE)Enables CDI bean discovery in the archive
spring.factoriesSpring Boot (pre-3.0)Lists auto-configuration classes for component scanning
spring/org.springframework.boot.autoconfigure.AutoConfiguration.importsSpring Boot 3.0+Replacement for spring.factories
web-fragment.xmlServlet 3.0+Declares servlets, filters, and listeners for modular web apps
INDEX.LISTJDKSpeeds up class loading by indexing package-to-JAR mappings

A typical JPA persistence.xml:

xml
1<persistence xmlns="https://jakarta.ee/xml/ns/persistence" version="3.0">
2  <persistence-unit name="default">
3    <class>com.example.model.User</class>
4    <class>com.example.model.Order</class>
5    <properties>
6      <property name="jakarta.persistence.jdbc.url"
7                value="jdbc:postgresql://localhost:5432/mydb"/>
8    </properties>
9  </persistence-unit>
10</persistence>

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).

plaintext
1myapp.jar                    myapp.war                    myapp.ear
2  META-INF/                    META-INF/                    META-INF/
3    MANIFEST.MF                  MANIFEST.MF                  MANIFEST.MF
4    services/                  WEB-INF/                       application.xml
5  com/example/...                web.xml                    lib/
6                                 classes/                   myejb.jar
7                                 lib/                       myweb.war

META-INF is always at the archive root; different containers look for different files inside it.

META-INF mistakes that break discovery

  • persistence.xml in the project root instead of META-INF. JPA will not find it and either fails silently or throws an opaque error about missing persistence units.
  • Confusing META-INF with WEB-INF. They have different visibility rules: META-INF files are reachable via ClassLoader.getResource(), while WEB-INF contents are reached through the ServletContext.
  • Naming services files after the implementation. Files in META-INF/services/ must be named with the fully qualified interface name. Reversed, ServiceLoader finds 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. ServiceLoader instantiates implementations lazily during iteration, which can hide startup errors until the service is first used.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data 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.

Practice algorithms