Whenever we encounter the “no main manifest attribute” message in a Spring Boot executable jar, it's because we're missing the declaration of the Main-Class metadata property from the file MANIFEST.MF, which is located under the META-INF folder.
In this short tutorial, we look at the causes of the problem and how to fix it.
2. When the Problem Occurs
Generally, we won't have any problems if we take our pom from Spring Initializr. However, if we build our project manually by adding the spring-boot-starter-parent to our pom.xml, we might experience the issue. We can replicate it by trying a clean build of the jar:
$ mvn clean package
We'd experience the error when running the jar:
$ java -jar target\spring-boot-artifacts-2.jar
no main manifest attribute, in target\spring-boot-artifacts-2.jar
In this example, the content of the MANIFEST.MF file is:
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.6.3 Built-By: Baeldung Build-Jdk: 11.0.13
3. Fixing With the Maven Plugin
3.1. Add the Plugin
The most common issue, in this case, is that we missed adding the spring-boot-maven-plugin declaration to our pom.xml file.
Let's add the plugin definition to our pom.xml with the Main-Class declaration under the plugins tag:
<plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.baeldung.demo.DemoApplication</mainClass> <layout>JAR</layout> </configuration> </plugin> </plugins>
However, this may not be enough to solve our issue. We might still receive “no main manifest attribute” message after rebuilding and running our jar.
Let's see what additional configurations and alternatives we have to solve this issue.
3.2. Maven Plugin Execution Goal
Let's add the repackage goal to the spring-boot-maven-plugin declaration right after the configuration tag:
<executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions>
3.3. Maven Properties and Inline Command Execution Goal
Alternatively, adding the property start-class to our pom.xml file's properties tag permits more flexibility in the build process:
<properties> <start-class>com.baeldung.demo.DemoApplication</start-class> </properties>
Now, we must build the jar by using the Maven inline command spring-boot:repackage execution goal:
$ mvn package spring-boot:repackage
4. Checking the MANIFEST.MF File Content
Let's apply our solutions, build the jar, and then check the MANIFEST.MF file.
We notice the presence of the Main-Class and Start-Class properties:
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.6.3 Built-By: Baeldung Build-Jdk: 11.0.13 Main-Class: org.springframework.boot.loader.JarLauncher Start-Class: com.baeldung.demo.DemoApplication Spring-Boot-Version: 2.7.5 Spring-Boot-Classes: BOOT-INF/classes/ Spring-Boot-Lib: BOOT-INF/lib/ Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx Spring-Boot-Layers-Index: BOOT-INF/layers.idx
Executing the jar now, the “no main manifest attribute” message issue is not showing up anymore, and the application runs.
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.
As always, the example code is available over on GitHub.