[Fixed] no main manifest attribute

In this post, we will see how to solve Unable to execute jar- file: “no main manifest attribute”.

Problem

When you have a self-executable jar and trying to execute it. You might get this error.

Unable to execute jar- file: “no main manifest attribute”

Solution

Maven

You might get this error when Main-Class entry is missing in MANIFEST.MF file. You can put maven-jar-plugin plugin in pom.xml to fix it.

org.arpit.java2blog.AppMain is a fully qualified name of main class. You need to replace it with your application’s main class.
Run mvn clean install and then execute the jar file as below.

AppMain-0.0.1-SNAPSHOT.jar is application jar that you want to run.

Spring boot application

In case, you are getting an error while running spring boot application, you can solve it with spring-boot-maven-plugin.

Gradle

In case you are using gradle, you can solve this with following entry.

Please replace org.arpit.java2blog.AppMain with your main class.

Root cause

When you run self-executable jar, java will look for the Main-Class in MANIFEST.MF file located under META-INF folder. If it is not able to find an entry,then it will complain with Unable to execute jar- file: “no main manifest attribute”.

MANIFEST.MF contains information about files contained in the Jar file.

Once you run the above-mentioned solution and reopen MANIFEST.MF file in jar again, you will see Main-Class entry.

This should solve Unable to execute jar- file: “no main manifest attribute”. Please comment in case you are still facing the issue.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *