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 -jar app.jar
no main manifest attribute, in app.jar
# or while building:
java.io.IOException: invalid manifest formatCommon 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.
<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.
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.
Manifest-Version: 1.0
Main-Class: com.example.App
# file MUST end with a trailing newlineHow to prevent it
- Let the build tool generate the manifest; avoid hand-editing MANIFEST.MF.
- Always set
Main-Classfor executable jars. - Respect the 72-byte line limit and trailing-newline rule if you must write one.