Run java jar - no main manifest attribute error

A manifest is a file in the path META-INF/MANIFEST.MF within the jar which defines attributes like the classpath and the main class for running the jar file.

The basic structure would be like:

Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)

You can define your entry point by adding the property Main-Class: classname.

In order to create your jar file with a given manifest you can:

  1. Use your IDE to add a manifest to the jar it generates.
  2. Use a command like jar cfm MyJar.jar Manifest.txt MyPackage/*.class to manually create a jar with the given manifest and classes.
  3. Manually decompress the jar, add the manifest, and compress it again. Compression tools generally could do this with a drag/drop.

You can find out more about the jar manifest file here.


You need a main class to execute you application. Try the following. It worked for me.

Add the following code snippet to your pom.xml file if you are using maven build tool.

 <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <build>
        <plugins>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.validator.App</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        </plugins>


    </build>

in my case, I was using spring-boot but i did not mentioned my builder in my pom so i fixed it by:

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

If you're using the Maven assembly plug-in, or your IDE tooling is, you need a mainClass element. This is what I use:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <mainClass>com.foo.MyMainClass</mainClass>
        </manifest>
      </archive>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
      <id>make-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      </execution>
    </executions>
  </plugin>