MANIFEST.MF difference between Main-Class and Start-Class
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Understanding the MANIFEST.MF File in Java Archives
The `MANIFEST.MF` file is an integral component of Java Archive (JAR) files, serving as a metadata descriptor for the JAR. It provides essential information such as package specifications and application entry points, which guide the Java Runtime Environment (JRE) on how to execute the JAR. Within this file, two attributes, `Main-Class` and `Start-Class`, often cause confusion due to their apparent similarity. However, they cater to different contexts and purposes.
The Role of MANIFEST.MF
The `MANIFEST.MF` file resides in the `META-INF` directory inside a JAR file. It can contain a variety of headers that provide information about files contained in the JAR, configuration options, and package-level metadata. Here's a simple example of what a `MANIFEST.MF` might look like:
- Definition: The `Main-Class` attribute specifies the class with the `public static void main(String[] args)` method used by the JRE as the starting point of a stand-alone Java application.
- Usage Context: It is primarily used for traditional, standalone Java applications.
- Technical Details:
- The specified class must reside within the JAR.
- The class path for all dependencies must be correctly defined either within the MANIFEST.MF or externally provided.
- Definition: `Start-Class` is predominantly used in frameworks like Spring Boot, which utilize an embedded servlet container to start web applications.
- Usage Context: It is used when deploying web applications and is not part of standard JAR specifications like `Main-Class`.
- Technical Details:
- It necessitates a launcher that recognizes the `Start-Class` attribute, such as Spring Boot's `JarLauncher`.
- This attribute is often part of a more complex bootstrapping process where additional configurations might be required.
- Purpose: Provides a way to include additional JAR files or directories as dependencies.
- Syntax: The paths are relative to the location of the JAR file.
- Limitations: For applications with extensive dependencies, managing via `Class-Path` can become cumbersome. Tools like `Maven` or `Gradle` can simplify dependency management.
Related reading
- Map enum in JPA with fixed values?
- Mapping list in Yaml to list of objects in Spring Boot
- MapStruct Lombok together not compiling unknown property in result type
- MAPSTRUCT. No property named packaging exists in source parameters
- Maven - Suppress Overriding managed version warning in Eclipse
- Maven – Always download sources and javadocs
- Maven add a dependency to a jar by relative path
- Maven and Spring Boot - non resolvable parent pom - repo.spring.io Unknown host

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.