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

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?

This question is related to java eclipse

The answer is


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.


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).


First run your application from eclipse to create launch configuration. Then just follow the steps:

  1. From the menu bar's File menu, select Export.
  2. Expand the Java node and select Runnable JAR file. Click Next.
  3. In the Runnable JAR File Specification page, select a 'Java Application' launch configuration to use to create a runnable JAR.
  4. In the Export destination field, either type or click Browse to select a location for the JAR file.
  5. Select an appropriate library handling strategy.
  6. Optionally, you can also create an ANT script to quickly regenerate a previously created runnable JAR file.

Source: Creating a New Runnable JAR File at Eclipse.org


You can select the "Runnable JAR File" after you click on "Export".

You can specify your main driver in "Launch Configuration"

enter image description here enter image description here


If you are using Spring boot, you should add this plugin in your pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Export you Java Project as an Runnable Jar file rather than Jar.

I exported my project as Jar and even though the Manifest was present it gave me the error no main manifest attribute in jar even though the Manifest file was present in the Jar. However there is only one entry in the Manifest file and it didn't specify the Main class or Function to execute or any dependent JAR's

After exporting it as Runnable Jar file it works as expected.


You need to include "Main class" attribute in Manisfest.mf file in Jar

For example: Main-Class: MyClassName

Second thing, To add Manifest file in Your jar, You can manually create file in your workspace folder, and refresh in Eclipse Project explorer.

While exporting, Eclipse will create a Jar which will include your manifest.

Cheers !!