Skip to content
Latchkey

jar "Invalid or corrupt jarfile / invalid manifest" - Fix in CI

The jar tool (or the JVM launching the jar) rejected the manifest. The MANIFEST.MF is malformed, missing the Main-Class attribute, or violates the manifest line-length/format rules.

What this error means

Building or running the jar fails with Invalid Manifest format, no main manifest attribute, in app.jar, or Error: Invalid or corrupt jarfile app.jar. The jar will not launch.

java
$ java -jar app.jar
no main manifest attribute, in app.jar

# or while building:
java.io.IOException: invalid manifest format

Common causes

Missing Main-Class attribute

An executable jar built without specifying the main class has no Main-Class: entry, so java -jar cannot launch it.

Malformed manifest formatting

A missing blank line at the end, a header line over 72 bytes not properly continued, or bad key: value formatting breaks parsing.

Hand-written manifest with wrong line breaks

A custom manifest with CRLF/encoding issues or unbroken long lines violates the JAR spec.

How to fix it

Set the Main-Class in the build

Let the build tool write a correct manifest with the entry point.

pom.xml
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive><manifest><mainClass>com.example.App</mainClass></manifest></archive>
  </configuration>
</plugin>

Set the manifest attribute (Gradle)

Configure the jar task manifest.

gradle
tasks.jar {
  manifest { attributes('Main-Class': 'com.example.App') }
}

Fix a hand-written manifest

Keep lines under 72 bytes (continue with a leading space) and end the file with a newline.

Terminal
Manifest-Version: 1.0
Main-Class: com.example.App
# file MUST end with a trailing newline

How to prevent it

  • Let the build tool generate the manifest; avoid hand-editing MANIFEST.MF.
  • Always set Main-Class for executable jars.
  • Respect the 72-byte line limit and trailing-newline rule if you must write one.

Frequently asked questions

What causes ""invalid manifest""?
An executable jar built without specifying the main class has no Main-Class: entry, so java -jar cannot launch it.
How do I fix "invalid manifest"?
Let the build tool write a correct manifest with the entry point.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card