Can't execute jar- file: "no main manifest attribute" in Spring Boot application

If you encounter the "No main manifest attribute" error when trying to run a Spring Boot application, you can fix it by following these steps:

1. Open the pom.xml file of your Spring Boot project and add the following plugin to the build section:

<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

This plugin is responsible for creating a runnable jar file with the necessary manifest attributes.

2. Save the changes and run the following command in your project directory to rebuild your project and create a new jar file:

mvn clean package

This will generate a new jar file with the necessary manifest attributes.

3. Now you can run your Spring Boot application using the following command:

java -jar target/your-project-name.jar

4. Replace "your-project-name" with the actual name of your project.

This should resolve the "No main manifest attribute" error and allow you to run your Spring Boot application.

In this article, we saw how to solve the “no main manifest attribute” message when executing a Spring Boot executable jar.

We saw how this can come from manually created pom.xml files and how to add and configure the Spring Maven plugin to fix it.