Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java can't execute jar file no main manifest attribute

Tags:

java

jar cvef Main.jar Main *

added manifest
adding: DrawPane.class(in = 344) (out= 257)(deflated 25%)
adding: DrawPane.java(in = 306) (out= 175)(deflated 42%)
adding: main(in = 9038) (out= 8275)(deflated 8%)
adding: Main.class(in = 868) (out= 544)(deflated 37%)
adding: Main.java(in = 507) (out= 260)(deflated 48%)
adding: Manifest.txt(in = 18) (out= 18)(deflated 0%)
adding: src/(in = 0) (out= 0)(stored 0%)
adding: src/icon.png(in = 1163) (out= 1168)(deflated 0%)
adding: src/Thumbs.db(in = 3584) (out= 1038)(deflated 71%)

jar file created, then:

java -jar Main.jar

I get an error:

no main manifest attribute, in Main.jar

what I'am doing wrong?

like image 939
yeah its me Avatar asked Jan 20 '14 17:01

yeah its me


People also ask

How do you fix no main manifest attribute?

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.

How do I run a JAR file manifest?

For a JAR file to run, the JAR itself must contain at least one class that has a runnable main method. Furthermore, the class with the main method must be listed as the main-class in the JAR's manifest file. If not, the class must be explicitly stated on the command line when the JAR is run.


2 Answers

As per this tutorial your manifest file should have relative path META-INF/MANIFEST.MF. It doesn't look like you added your own manifest there. The jar command adds a default manifest, that's why it says 'manifest added'.

EDIT: As per the next page in the tutorial, the basic syntax to add content to the manifest file is the following:

jar cfm jar-file manifest-addition input-file(s)

I recommend to read the first few section of the tutorial and I'm sure you'll get the result you want!

like image 150
Giovanni Botta Avatar answered Sep 21 '22 15:09

Giovanni Botta


make sure to write 1 space after ":" and new line after class name and save it that way. jar tool syntax:

 jar -cvmf manifest.txt appname.jar ClassName.class

after running tool , run jar file with

java -jar appname.jar

Content of manifest.txt file

Main-Class:(1space)ClassName(press enter for new line)

Hope it helps

like image 23
Pradida Avatar answered Sep 18 '22 15:09

Pradida