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

+2 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,300 points
27,602 views

10 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,540 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
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

Related Questions In Java

0 votes
1 answer

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

The proper syntax to run a jar ...READ MORE

answered Apr 22 in Java by Omkar
• 67,660 points
291 views
+5 votes
3 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,380 points

edited Nov 6, 2018 by Omkar 10,070 views
+2 votes
10 answers

How to import a jar file in Eclipse?

To import jar file in your Eclipse ...READ MORE

answered May 15, 2018 in Java by sharth
• 3,350 points
68,985 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
1,519 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,640 points
1,379 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 parth295
• 4,640 points
100 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 parth295
• 4,640 points
1,116 views
0 votes
2 answers

“Could not find or load main class” mean?

Use the final modifier to enforce good initialization. Avoid returning ...READ MORE

answered Sep 18, 2018 in Java by Sushmita
• 6,880 points
1,800 views
+9 votes
11 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,540 points
43,020 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,880 points
253 views