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:
- Open the pom.xml file of your Spring Boot application.
- 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.
- 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.
- 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.
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
You can download the full source code of this example here: No Main Manifest Attribute in Spring Boot