manifest.mf
main-class
start-class
java
java-application

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.

Browse interview questions

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

Browse interview questions

All Rights Reserved.