First, it’s kind of weird, to see you run java -jar "app" and not java -jar app.jar
Second, to make a jar executable… you need to jar a file called META-INF/MANIFEST.MF
the file itself should have (at least) this one liner:
Main-Class: com.mypackage.MyClass
Where com.mypackage.MyClass is the class holding the public static void main(String[] args) entry point.
Note that there are several ways to get this done either with the CLI, Maven, Ant or Gradle:
For CLI, the following command will do: (tks @dvvrt)
jar cmvf META-INF/MANIFEST.MF <new-jar-filename>.jar <files to include>
For Maven, something like the following snippet should do the trick. Note that this is only the plugin definition, not the full pom.xml:
Latest doc on this plugin: see https://maven.apache.org/plugins/maven-jar-plugin/
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mypackage.MyClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
(Pick a <version> appropriate to your project.)
For Ant, the snippet below should help:
<jar destfile="build/main/checksites.jar">
<fileset dir="build/main/classes"/>
<zipfileset includes="**/*.class" src="lib/main/some.jar"/>
<manifest>
<attribute name="Main-Class" value="com.acme.checksites.Main"/>
</manifest>
</jar>
Credits Michael Niemand —
For Gradle:
plugins {
id 'java'
}
jar {
manifest {
attributes(
'Main-Class': 'com.mypackage.MyClass'
)
}
}
First, it’s kind of weird, to see you run java -jar "app" and not java -jar app.jar
Second, to make a jar executable… you need to jar a file called META-INF/MANIFEST.MF
the file itself should have (at least) this one liner:
Main-Class: com.mypackage.MyClass
Where com.mypackage.MyClass is the class holding the public static void main(String[] args) entry point.
Note that there are several ways to get this done either with the CLI, Maven, Ant or Gradle:
For CLI, the following command will do: (tks @dvvrt)
jar cmvf META-INF/MANIFEST.MF <new-jar-filename>.jar <files to include>
For Maven, something like the following snippet should do the trick. Note that this is only the plugin definition, not the full pom.xml:
Latest doc on this plugin: see https://maven.apache.org/plugins/maven-jar-plugin/
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mypackage.MyClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
(Pick a <version> appropriate to your project.)
For Ant, the snippet below should help:
<jar destfile="build/main/checksites.jar">
<fileset dir="build/main/classes"/>
<zipfileset includes="**/*.class" src="lib/main/some.jar"/>
<manifest>
<attribute name="Main-Class" value="com.acme.checksites.Main"/>
</manifest>
</jar>
Credits Michael Niemand —
For Gradle:
plugins {
id 'java'
}
jar {
manifest {
attributes(
'Main-Class': 'com.mypackage.MyClass'
)
}
}
First, it’s kind of weird, to see you run java -jar "app" and not java -jar app.jar
Second, to make a jar executable… you need to jar a file called META-INF/MANIFEST.MF
the file itself should have (at least) this one liner:
Main-Class: com.mypackage.MyClass
Where com.mypackage.MyClass is the class holding the public static void main(String[] args) entry point.
Note that there are several ways to get this done either with the CLI, Maven, Ant or Gradle:
For CLI, the following command will do: (tks @dvvrt)
jar cmvf META-INF/MANIFEST.MF <new-jar-filename>.jar <files to include>
For Maven, something like the following snippet should do the trick. Note that this is only the plugin definition, not the full pom.xml:
Latest doc on this plugin: see https://maven.apache.org/plugins/maven-jar-plugin/
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mypackage.MyClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
(Pick a <version> appropriate to your project.)
For Ant, the snippet below should help:
<jar destfile="build/main/checksites.jar">
<fileset dir="build/main/classes"/>
<zipfileset includes="**/*.class" src="lib/main/some.jar"/>
<manifest>
<attribute name="Main-Class" value="com.acme.checksites.Main"/>
</manifest>
</jar>
Credits Michael Niemand —
For Gradle:
plugins {
id 'java'
}
jar {
manifest {
attributes(
'Main-Class': 'com.mypackage.MyClass'
)
}
}
Содержание
- How to fix “no main manifest attribute” error
- Why «no main manifest attribute»?
- Putting maven-jar-plugin in pom.xml
- Specify Main-Class in Gradle
- Change default MANIFEST.MF folder in IntelliJ IDEA
- Specify entry point in Eclipse
- How to fix “no main manifest attribute” error
- Why «no main manifest attribute»?
- Putting maven-jar-plugin in pom.xml
- Specify Main-Class in Gradle
- Change default MANIFEST.MF folder in IntelliJ IDEA
- Specify entry point in Eclipse
- [Fixed] no main manifest attribute
- Problem
- Solution
- Maven
- Spring boot application
- Gradle
- Root cause
- Was this post helpful?
- Share this
- Related Posts
- Author
- Related Posts
- [Fixed] Unsupported class file major version 61 in Java
- [Fixed] java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
- [Fixed] java.util.HashMap$Values cannot be cast to class java.util.List
- [Fixed] Unable to obtain LocalDateTime from TemporalAccessor
- «No main manifest attribute» when creating Kotlin jar using IntelliJ IDEA
- 4 Answers 4
- No main manifest attribute, in jar
- Problem
- Solution
- Take time to understand !
How to fix “no main manifest attribute” error
Every executable jar file in a Java application should contain a main method. It is usually placed at the beginning of the application. Manifest files must be included with self-executing jars, as well as being wrapped in the project at the appropriate location, to run a main method. Manifest files have a main attribute that specifies the class having the main method.
«no main manifest attribute» is a common error which happens when we try to run an executable jar file. The full error output may look like what’s shown below
In this article, we will show you a few possible fix that you can apply to your Java project to avoid getting «no main manifest attribute» error.
Why «no main manifest attribute»?
«no main manifest attribute» error message is thrown because of various reasons, but most of the time, it fall under one of the following category.
- Missing entry point of Main-Class in MANIFEST.MF file.
- Missing Maven dependency in pom.xml
- Missing entry point in build.gradle
The Main, or Main-Class is an essential attribute to make your jar executable. It tells Java which class would be used as the entry point of the application.
Without a Main , or Main-Class attribute, Java have no way to know which class it should run when you execute the jar .
Inside the jar file, the MANIFEST.MF file is located in META-INF folder. Opening the jar file with WinRAR, you would see the contents of it, along with MANIFEST.MF .
A typical MANIFEST.MF file should contain the following lines
Below is an example of a MANIFEST.MF file.
Putting maven-jar-plugin in pom.xml
The «no main manifest attribute» error message may occur in a Maven project due to the absence of the Main-Class entry in MANIFEST.MF.
This issue can be resolved by adding maven-jar-plugin to our pom.xml file.
In the code snippet above, com.linuxpip.AppMain is our fully-qualified name of the Main-Class. You have to change this according to your specific project.
If you need more information, dig deep into maven-jar-plugin documentation: see https://maven.apache.org/plugins/maven-jar-plugin/
Specify Main-Class in Gradle
The following entries can be put into your build.gradle file if you receive this error in your Gradle project:
In the code snippet above, com.linuxpip.MyClass is our fully-qualified name of the Main-Class. You have to change this according to your specific project.
Change default MANIFEST.MF folder in IntelliJ IDEA
People have been reporting that IntelliJ IDEA keeps putting the JAR artifact into the wrong folder.
In order to fix «no main manifest attribute» in IntelliJ IDEA, choose JAR > From modules with dependencies
In the Create JAR from Modules window, change the default Directory for META-INF/MANIFEST.MF path from
Otherwise it would generate the manifest and including it in the jar, but not the one in
srcmainjava that Java expects.
After that, just continue to Build Artifacts as you usually do.
Specify entry point in Eclipse
If you’re exporting the JAR file in Eclipse, it has a built-in option that allows you to specify the Application’s entry point, avoiding «no main manifest attribute» error message.
Источник
How to fix “no main manifest attribute” error
Every executable jar file in a Java application should contain a main method. It is usually placed at the beginning of the application. Manifest files must be included with self-executing jars, as well as being wrapped in the project at the appropriate location, to run a main method. Manifest files have a main attribute that specifies the class having the main method.
«no main manifest attribute» is a common error which happens when we try to run an executable jar file. The full error output may look like what’s shown below
In this article, we will show you a few possible fix that you can apply to your Java project to avoid getting «no main manifest attribute» error.
Why «no main manifest attribute»?
«no main manifest attribute» error message is thrown because of various reasons, but most of the time, it fall under one of the following category.
- Missing entry point of Main-Class in MANIFEST.MF file.
- Missing Maven dependency in pom.xml
- Missing entry point in build.gradle
The Main, or Main-Class is an essential attribute to make your jar executable. It tells Java which class would be used as the entry point of the application.
Without a Main , or Main-Class attribute, Java have no way to know which class it should run when you execute the jar .
Inside the jar file, the MANIFEST.MF file is located in META-INF folder. Opening the jar file with WinRAR, you would see the contents of it, along with MANIFEST.MF .
A typical MANIFEST.MF file should contain the following lines
Below is an example of a MANIFEST.MF file.
Putting maven-jar-plugin in pom.xml
The «no main manifest attribute» error message may occur in a Maven project due to the absence of the Main-Class entry in MANIFEST.MF.
This issue can be resolved by adding maven-jar-plugin to our pom.xml file.
In the code snippet above, com.linuxpip.AppMain is our fully-qualified name of the Main-Class. You have to change this according to your specific project.
If you need more information, dig deep into maven-jar-plugin documentation: see https://maven.apache.org/plugins/maven-jar-plugin/
Specify Main-Class in Gradle
The following entries can be put into your build.gradle file if you receive this error in your Gradle project:
In the code snippet above, com.linuxpip.MyClass is our fully-qualified name of the Main-Class. You have to change this according to your specific project.
Change default MANIFEST.MF folder in IntelliJ IDEA
People have been reporting that IntelliJ IDEA keeps putting the JAR artifact into the wrong folder.
In order to fix «no main manifest attribute» in IntelliJ IDEA, choose JAR > From modules with dependencies
In the Create JAR from Modules window, change the default Directory for META-INF/MANIFEST.MF path from
Otherwise it would generate the manifest and including it in the jar, but not the one in
srcmainjava that Java expects.
After that, just continue to Build Artifacts as you usually do.
Specify entry point in Eclipse
If you’re exporting the JAR file in Eclipse, it has a built-in option that allows you to specify the Application’s entry point, avoiding «no main manifest attribute» error message.
Источник
[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.
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?
[Fixed] Reached end of file while parsing
[Fixed] insert dimensions to complete referencetype

[Fixed] Unsupported class file major version 61 in Java
Table of ContentsReason for Unsupported class file major version 61 in JavaSolution for Unsupported class file major version 61 in JavaAndorid studio/Intellij Idea with gradleAny other scenario In this post, we will see how to fix Unsupported class file major version 61 in Java. Reason for Unsupported class file major version 61 in Java You […]

[Fixed] java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
Table of ContentsReason for java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayListFixes for java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayListUse ArrayList’s constructorAssign Arrays.asList() to List reference rather than ArrayList In this post, we will see how to fix java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList. ClassCastException is runtime exception which indicate that code has tried to […]

[Fixed] java.util.HashMap$Values cannot be cast to class java.util.List
Table of ContentsWhy HashMap values cannot be cast to list?Fix for java.util.HashMap$Values cannot be cast to class java.util.List In this post, we will see how to fix error java.util.HashMap$Values cannot be cast to class java.util.List. Why HashMap values cannot be cast to list? HashMap values returns java.util.Collection and you can not cast Collection to List […]

[Fixed] Unable to obtain LocalDateTime from TemporalAccessor
Table of ContentsUnable to obtain LocalDateTime from TemporalAccessor : ReasonUnable to obtain LocalDateTime from TemporalAccessor : FixLocalDate’s parse() method with atStartOfDay()Use LocalDate instead of LocalDateTime In this article, we will see how to fix Unable to obtain LocalDateTime from TemporalAccessor in Java 8. Unable to obtain LocalDateTime from TemporalAccessor : Reason You will generally get […]
Источник
«No main manifest attribute» when creating Kotlin jar using IntelliJ IDEA
When creating a jar from my Kotlin code and running it, it says «No main manifest attribute». When looking at the manifest.mf, it has this content:
When looking at the file in the source, it has this content:
When manually copying the source manifest to the jar, it runs perfectly.

4 Answers 4
I got this error with Gradle and Kotlin. I had to add in my build.gradle.kts an explicit manifest attribute:
From the gradle documentation, it’s better to create a fatJar task to englobe all of the runtime dependencies in case you encounter java.lang.NoClassDefFoundError errors

If any of the dependent jars has a MANIFEST.MF file, it will override your custom one which defines the Main-Class .
In order to address this problem you should do the following:
- Disable the alphabetical ordering
- Change items ordering so that item which has META-INF/MANIFEST.MF file is the first in the list
- Your custom MANIFEST.MF will be picked up by IntelliJ IDEA and displayed for the jar artifact.
See the related issue for more details.
You can also use Gradle or Maven to generate the fat jar instead.
Источник
No main manifest attribute, in jar
Table of contents
Problem
Sometimes you face the following error while runing an executable jar :
Solution
- Main-class property is missing on your jars META-INF/MANIFEST.MF. Correct it by adding the following lines to your pom.xml
Consider that the the fully qualified name of your Main class is com.roufid.tutorials.AppTest
- Launch a clean install on your application
Take time to understand !
Since your are running an executable jar file, Java will look for the manifest MANIFEST.MF located under META-INF/ which contains information about the files packaged.
Java must know the main class to run. This information was missing in the MANIFEST.MF. Below the content of this file before adding the maven-jar-plugin :
There is no mention of a Main-Class !
We used maven-jar-plugin to handle jar content and manifest configuration, specially adding a Main-Class property to MANIFEST.MF file to specify the project main class. Below the aim of the property :
- com.roufid.tutorials.AppTest
Is to make our Jar executable. You must set here the fully qualified name of your Main class.
The manifest classpath produced using the above configuration would look like this:
Источник