SpringBoot no main manifest attribute maven
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Understanding the "No Main Manifest Attribute" Error in Spring Boot with Maven
The "no main manifest attribute" error is a common issue encountered when working with Spring Boot applications, especially during the packaging phase using Maven. This error occurs when the Java runtime is unable to find the Main-Class entry in the JAR file's manifest, which specifies the entry point of the application.
What Triggers the "No Main Manifest Attribute" Error?
When you run a JAR file using the command java -jar myapp.jar, the Java runtime looks for a META-INF/MANIFEST.MF file within the JAR. This manifest file should contain a Main-Class attribute pointing to the entry point of your Spring Boot application. If this attribute is missing, Java will not know where to start execution, leading to the "no main manifest attribute" error.
Technical Explanation
Spring Boot applications are usually packaged as executable JARs. This process is often facilitated by the Spring Boot Maven Plugin. Here's how it typically works:
- Project Setup: A typical Spring Boot application follows a prescribed structure where the entry point class is annotated with
@SpringBootApplication. This class contains a main method, which is the entry point.
- Maven Configuration: The
spring-boot-maven-pluginhandles the creation of an executable JAR, including the generation of theMANIFEST.MFfile with the necessaryMain-Classattribute.
Resolving the Error
To fix the "no main manifest attribute" error, you need to ensure that your Maven build correctly sets up the JAR manifest file. Here are steps to ensure this:
- Use the Spring Boot Maven Plugin: Ensure that the
spring-boot-maven-pluginis properly added to your project'spom.xml. This plugin automatically generates a manifest with the main class.
- Verify the Main Class: Make sure that your main application class is correctly annotated and located. This is typically done by annotation with
@SpringBootApplicationand located within thesrc/main/javadirectory. - Clean and Rebuild the Project: Sometimes, issues arise from stale build artifacts. Perform a clean build:
- Check the Manifest File: You can manually inspect the generated JAR to verify if the
MANIFEST.MFcontains theMain-Classentry. Use a tool likejaror a tool with GUI support for JAR inspection:
You should see an entry similar to the following:
or
Additional Considerations
- Custom Main-Class Setup: If you must explicitly define a different main class, you can do so in your Maven
pom.xml.
- Multi-Module Projects: Ensure that for multi-module Maven projects, only the main module intended to be the runnable JAR has the Spring Boot plugin configured to produce an executable JAR.
Summary Table
| Checkpoint | Description |
| Spring Application Entry Point | Annotate the main class with @SpringBootApplication |
| Maven Plugin Configuration | Use spring-boot-maven-plugin in pom.xml |
| Build Process | Use mvn clean package to build the JAR |
| Jar Inspection | Inspect MANIFEST.MF for Main-Class attribute |
| Custom Main-Class (Optional) | Define custom mainClass in plugin configuration |
Understanding and addressing the "no main manifest attribute" error can enhance productivity in Spring Boot projects, ensuring that your applications are packaged and run correctly using Maven. With the proper setup, this issue can be effectively mitigated, allowing for efficient deployment and execution of robust Java applications.

