spring

No Main Manifest Attribute in Spring Boot

When building a Spring Boot application, you may encounter an error message that says “no main manifest attribute” when you try to run the application. This error occurs because the Java Virtual Machine (JVM) cannot find the main class that it needs to execute the application.

1. Manifest File

The main class is defined in the application’s manifest file. The manifest file is a metadata file that contains information about the application, including the main class. The manifest file is usually located in the META-INF directory of the application’s JAR file.

2. Resolve the “no main manifest attribute” error

To resolve the “no main manifest attribute” error, you need to make sure that the main class is specified in the application’s manifest file. Here are the steps to do that:

  1. Open the pom.xml file of your Spring Boot application.
  2. Add the following configuration to the build section of the pom.xml file:
<plugins>
  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring-boot.version}</version>
    <configuration>
      <mainClass>com.example.Application</mainClass>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>repackage</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>

This configuration tells the Spring Boot Maven plugin to include the main class in the manifest file.

  1. Run the following Maven command to rebuild the application:
mvn clean package

This command will rebuild the application and create a new JAR file that includes the main class in the manifest file.

Fig. 1: Spring Boot with main manifest attribute Specified.
Fig. 1: Spring Boot with main manifest attribute Specified.
  1. Run the application using the following command:
java -jar target/myapp-1.0.0.jar

This command will start the Spring Boot application with the main class specified in the manifest file.

Fig. 2: Runnig Spring Boot App.
Fig. 2: Runnig Spring Boot App.

3. Conclusion

In summary, the “no main manifest attribute” error can be resolved by specifying the main class in the application’s manifest file. By following the steps outlined above, you can ensure that your Spring Boot application runs without any issues.

4. Download the Source Code

Download
You can download the full source code of this example here: No Main Manifest Attribute in Spring Boot

Want to know how to develop your skillset to become a Java Rockstar?

Join our newsletter to start rocking!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Odysseas Mourtzoukos

Mourtzoukos Odysseas is studying to become a software engineer, at Harokopio University of Athens. Along with his studies, he is getting involved with different projects on gaming development and web applications. He is looking forward to sharing his knowledge and experience with the world.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button