Unable to execute jar- file no main manifest attribute

+3 votes

Announcement! Career Guide 2019 is out now. Explore careers to become a Big Data Developer or Architect!

I have installed an application, when I try to run it (it's an executable jar) nothing happens. When I run it from the commandline with:

java -jar "app.jar"

I get the following message:

no main manifest attribute, in "app.jar"

Normally, if I had created the program myself, I would have added a main class attribute to the manifest file. But in this case, since the file is from an application, i cannot do that. I also tried extracting the jar to see if I could find the main class, but there are to many classes and none of them has the word "main" in it's name. There must be a way to fix this because the program runs fine on other systems.

Jun 18, 2018 in Java by developer_1
• 3,350 points
216,442 views

13 answers to this question.

0 votes

That should have been java -jar app.jar instead of java -jar "app".

The -jar option only works if the JAR file is an executable JAR file, which means it must have a manifest file with a Main-Class attribute in it. See Packaging Programs in JAR Files to learn how to create an executable JAR.

If it's not an executable JAR, then you'll need to run the program with something like:

java -cp app.jar com.somepackage.SomeClass

where com.somepackage.SomeClass is the class that contains the main method to run the program. (What that class is depends on the program, it's impossible to tell from the information you've supplied).

answered Jun 18, 2018 by Rishabh
• 3,620 points
+1 vote

add a jar/manifest/attributes setting like this:

apply plugin: 'java'
jar {
    manifest {
        attributes 'Main-Class': 'com.package.app.Class'
    }
}
answered Nov 27, 2018 by krishti
I got error like this.c an you please tell me the solution for this error?

"C:\Program Files\Android\Android Studio\jre\bin\java.exe" -Dfile.encoding=windows-1252 -jar C:\Users\lb53616\Documents\cyient\watermarkImagesWorkspace\gradle\wrapper\gradle-wrapper.jar
no main manifest attribute, in C:\Users\lb53616\Documents\cyient\watermarkImagesWorkspace\gradle\wrapper\gradle-wrapper.jar

Process finished with exit code 1

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

0 votes

Main-class property is missing on your jars META-INF/MANIFEST.MF. Correct it by adding the following lines to your pom.xml

build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.roufid.tutorials.AppTest</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
answered Nov 27, 2018 by Layla
0 votes

Try adding this to your jar file:

java -cp yourJarName.jar your.package..your.MainClass
answered Nov 27, 2018 by Eric
0 votes

Try this command to include the jar:

java -cp yourJarName.jar your.package..your.MainClass
answered Dec 10, 2018 by Rishav
0 votes

When I got the problem I re-created the jar artifact, choosing JAR > From modules with dependencies, but not accepting the default Directory for META-INF/MANIFEST.MF.
Change it from -/src/main/java to -/src/main/resources.

answered Dec 10, 2018 by Shuvodip
0 votes

I had the manifest file in correct place, containing the Main-Class and everything. What tripped me over was this:

Warning: The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.

Adding a newline at the end of the manifest fixed it.

answered Dec 10, 2018 by bugseeker
0 votes

I had the same issue. by adding following lines to pom file made it work.
The plugin will make sure the build process of your application with all necessary steps.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
answered Dec 10, 2018 by Rachel
0 votes

If u're using gradle, just add next one in ur gradle.build:

apply plugin: 'java'

jar {
    manifest {
        attributes 'Main-Class': 'com.company.project.MainClass'
    }
}
answered Dec 10, 2018 by findingbugs
0 votes

You Can Simply follow this step Create a jar file using

 jar -cfm jarfile-name manifest-filename Class-file name

While running the jar file simple run like this

 java -cp jarfile-name main-classname
answered Dec 10, 2018 by Sukesh
0 votes
I made a calculator using Java AWT completely by hand, no IDE, just notepad++, and compiled the program. This made two class files, one is basically the calculator graphics class and the other is the main class, with the main method which creates the calculator (i.e. I didn't include the main method inside the calculator class, I instead included it in a separate class).
answered Apr 13, 2020 by beenmeckel
• 180 points
0 votes

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:

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:

<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'
        )
    }
}
answered Dec 10, 2020 by Roshni
• 10,480 points
0 votes

That is because Java cannot find the Main attribute in the MANIFEST. MF file. The Main attribute is necessary to tell java which class it should use as the application's entry point. Inside the jar file, the MANIFEST. ... You get this "no main manifest attribute" error when this line is missing from the MANIFEST

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

answered Dec 10, 2020 by Rajiv
• 8,870 points

Related Questions In Java

0 votes
2 answers

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

Check out the answer here. READ MORE

answered Apr 23, 2020 in Java by Anonymous
3,214 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,240 views
+5 votes
11 answers

How to import a jar file in Eclipse?

Click on File > Import. The Import ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
359,822 views
0 votes
1 answer

How can we add local .jar file dependency to build.gradle file?

You can refer the below code if ...READ MORE

answered Jun 27, 2018 in Java by Akrati
• 960 points
5,367 views
0 votes
1 answer

Can't execute jar- file: “no main manifest attribute”

First, it's kind of weird, to see ...READ MORE

answered Dec 23, 2020 in Java by Gitika
• 65,770 points
2,662 views
0 votes
1 answer

Retrieving the path of a running jar file

Its quite simple. Try using the below ...READ MORE

answered May 25, 2018 in Java by geek.erkami
• 2,680 points
10,709 views
0 votes
1 answer

How to run the JAR files in windows?

Following are the steps to run the ...READ MORE

answered May 28, 2018 in Java by Parth
• 4,640 points
1,144 views
0 votes
1 answer

How to run a JAR file in Java?

The command given below will help you ...READ MORE

answered Jun 1, 2018 in Java by Parth
• 4,640 points
7,424 views
+9 votes
16 answers

Unable to resolve this error: "javac is not recognized as an internal or external command"

Check your javac path on Windows using Windows Explorer C:\Program Files\Java\jdk1.7.0_02\bin and ...READ MORE

answered May 23, 2018 in Java by Rishabh
• 3,620 points
463,950 views
0 votes
2 answers

How can we add the local JAR files to the Maven Project in Java?

Firstly I would like to give credit ...READ MORE

answered Nov 5, 2018 in Java by Sushmita
• 6,920 points
11,797 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP