Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing to run jar file from command line: “no main manifest attribute”

Tags:

java

eclipse

I am trying to run a jar file from the console:

java -jar ScrumTimeCaptureMaintenence.jar

And am getting the error:

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

As you can see I do in fact have a main file and it runs fine from eclipse:

main method is in class

What do I need to do to successfully run this file from the command line?

like image 542
David Tunnell Avatar asked Oct 08 '13 14:10

David Tunnell


3 Answers

Try to run

java -cp ScrumTimeCaptureMaintenence.jar Main
like image 91
Milan Baran Avatar answered Nov 20 '22 00:11

Milan Baran


In Eclipse: right-click on your project -> Export -> JAR file

At last page with options (when there will be no Next button active) you will see settings for Main class:. You need to set here class with main method which should be executed by default (like when JAR file will be double-clicked).

like image 31
Pshemo Avatar answered Nov 19 '22 23:11

Pshemo


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.

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.

like image 18
spacewanderer Avatar answered Nov 19 '22 23:11

spacewanderer