How to Fix “No Main Manifest Attribute” in a JAR
To fix no main manifest attribute in a JAR, set the manifest’s Main-Class attribute to your application’s fully qualified entry-point class, or launch that class explicitly on the classpath. The message means Java cannot find the entry point needed for direct JAR execution; it is not an attribute you set to “no.” Use the symptoms below to choose a repair before changing the archive.
| Symptom | Likely Cause | Appropriate Fix |
|---|---|---|
Starting a JAR produces no main manifest attribute |
The archive lacks an executable entry point, or it is a library | Configure the application’s main class or use its supplied launcher |
| A manifest exists, but the error remains | The manifest was not packaged correctly, or you are running a different JAR | Inspect the manifest inside the exact file being launched |
| The application runs in an IDE but not as a JAR | The IDE supplies launch settings that the packaged artifact lacks | Configure the packaging tool |
| A main-class or dependency error appears after the change | Java now has an entry point but cannot load the required classes | Correct the class name, archive layout, or runtime dependencies |
What the Missing Main Manifest Attribute Means
A JAR can be a valid archive without being directly executable.
A JAR stores compiled classes and resources. When you use Java’s -jar launch mode, Java needs the manifest to identify the class that starts the application. For an ordinary executable JAR, that header looks like this:
Main-Class: com.example.Main
The value is a Java class name, not a source filename or filesystem path. Adding the header does not create a main method, compile missing classes, or bundle dependencies.
Library JARs often have no entry point because another application loads their classes. They do not need this error “fixed” unless they were actually intended to be standalone applications.
How to Fix the JAR’s Missing Entry Point
Verify the entry-point class before changing an ordinary application JAR’s manifest; the examples use app.jar and com.example.Main. Substitute your actual archive and entry-point class. Use a current JDK so the jar, javap, and javac tools are available.
Step 1: Inspect the Exact JAR You Are Running
- List the archive’s contents:
jar --list --file app.jar - Open the same archive with a ZIP-capable archive viewer and inspect
META-INF/MANIFEST.MF, if present. Check the file inside the archive, not a similarly named file beside it. TheMETA-INFdirectory is optional in the JAR format, so its absence alone does not mean the archive is malformed, according to the JAR File Specification. - Look for the application’s compiled entry class. For the example class name, its archive entry should be:
com/example/Main.class - Check whether
module-info.classappears at the JAR root before treating the archive as an ordinary classpath JAR. Its presence identifies a modular JAR; a multi-release JAR can also carry a module descriptor in a versioned directory.
If this is an unfamiliar downloaded application, first establish whether you have its runnable distribution or just one of its libraries. Do not choose an arbitrary class and insert it into the manifest.
Step 2: Identify and Test the Entry-Point Class
- Identify the intended startup class from the source code or application’s launch configuration. For broad compatibility across Java versions, the conventional entry method is:
public static void main(String[] args) - If you know the candidate class name but do not have the source, inspect its declared members:
javap -classpath app.jar com.example.MainLook for the conventional main method. Use the package-qualified class name with dots, without a
.classsuffix. - For an ordinary application JAR that needs no external runtime libraries, test an explicit-class launch:
java -cp app.jar com.example.Main
If the application starts, this is already a complete workaround: explicit-class launching does not need a manifest entry point. Continue only if you also want direct JAR launching to work.
If Java cannot find the class or a required dependency, correct that problem before editing the manifest. A manifest header cannot repair missing application files.
Step 3: Add the Main Class to Your Application JAR
- Back up your own unsigned application JAR, then use the jar tool to set Main-Class to the application’s fully qualified entry-point class. Leave signed third-party archives unchanged: modifying their manifests can invalidate signatures.
- Set the entry point with the JDK’s packaging tool:
jar --update --file app.jar --main-class com.example.Main
This updates the archive’s manifest directly. The jar tool handles manifest serialization without requiring you to hand-edit ZIP contents.
For projects built with Maven or Gradle, treat this as an immediate repair, not a permanent build change. A later build can replace the patched archive.
Step 4: Launch the Updated Archive
- Run the file you just updated:
java -jar app.jar - Confirm that the application reaches its expected startup state: for a console program, that might be its normal output; for a service, its ready message.
A new error is useful diagnostic information, but it is not a successful finish. For example, “Could not find or load main class” usually means the configured class name or packaged location is wrong. A missing-dependency exception means the launcher found the entry point but could not load everything the application requires.
Manifest Text Files for New JAR Builds
A text manifest is useful when you want an inspectable file that your packaging command consumes. Save the source as Main.java and include package com.example; before the class declaration.
- Save this source as
src/com/example/Main.java:package com.example; public class Main { public static void main(String[] args) { System.out.println("Hello from the JAR"); } } - Use a colon followed by a space between each header name and value. End the final header with a newline, and terminate the main section with a blank line. Keep the entry-point header in that main section, before its terminating blank line. Headers in later, per-entry sections do not define the application’s startup class. Manifest lines must not exceed 72 bytes in UTF-8, not characters. A continuation line begins with a single space. For long attribute values, let a manifest-writing tool handle wrapping rather than splitting multibyte text by hand.
- Compile the source into an output directory:
javac -d out src/com/example/Main.java - Package the compiled output with your text manifest:
jar --create --file app.jar --manifest manifest.txt -C out .The
-C out .portion places the contents ofoutat the archive root. It does not add an extraoutdirectory above your package structure. - Launch the completed JAR:
java -jar app.jar
The expected output is:
Hello from the JAR
If you are automating this in Java, do not use JarURLConnection to change the archive. It is read-only and cannot provide an OutputStream for modifying a JAR, as documented in the JarURLConnection API. Use a packaging tool or an archive-writing API instead.
Build-Tool Fixes for Maven and Gradle
Put the entry-point configuration in the build so every newly generated artifact contains it. The plain-JAR configurations below set the launcher metadata; they do not bundle external dependencies.
Plain Maven Applications
For a standard Maven application, merge this plugin configuration into the existing <build><plugins> section of pom.xml. Preserve any plugin version already pinned by your project.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Replace the example class with your application’s entry point, then rebuild:
mvn clean package
Run the JAR Maven generated in target. For a project whose output is kafkamocktest-1.0-SNAPSHOT.jar, the command is:
java -jar target/kafkamocktest-1.0-SNAPSHOT.jar
Use the actual filename shown in your build output; its capitalization matters on case-sensitive filesystems.
If startup now fails on a dependency, the missing entry point is repaired, but the runtime distribution is still incomplete.
Plain Gradle Applications
In a project with Gradle’s java or application plugin applied, add this to build.gradle using the Groovy DSL:
tasks.named('jar') {
manifest {
attributes('Main-Class': 'com.example.Main')
}
}
Build with the Gradle wrapper on macOS or Linux:
./gradlew clean jar
On Windows, use:
.\gradlew.bat clean jar
Then run the generated JAR in build/libs, substituting its actual filename:
java -jar build/libs/app-1.0.jar
Confirm that the application starts normally.
If you already use the application plugin, its mainClass setting controls the application’s run task and generated launch scripts.
Spring Boot Applications Built With Maven
In a Maven project already using Spring Boot’s parent or managing a compatible Boot plugin version, merge this into <build><plugins>:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.Application</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Use your actual Spring Boot application class, then rebuild:
mvn clean package
Run the repackaged artifact, using its actual filename:
java -jar target/app-1.0-SNAPSHOT.jar
Confirm that Boot completes application startup. Do not launch the original, unrepackaged archive.
In a Boot executable JAR, the manifest’s main class is normally Boot’s launcher, while Start-Class identifies your application class. Let the Boot plugin generate those attributes rather than replacing the launcher with your application class by hand.
Third-Party, Library, and Modular JARs
Some archives should not be repaired by adding an entry-point header. Their intended launch mechanism determines the right action.
Downloaded Applications and Library JARs
For a downloaded application, use its supplied launch script or executable distribution when available. A script can supply dependency paths, JVM options, and application configuration that a bare JAR launch lacks.
Check that you did not select a -sources.jar, -javadoc.jar, or a framework’s plain, unrepackaged artifact. Those files can be valid build outputs without being the executable application.
If the archive is a library, keep it as a dependency. Adding an arbitrary entry-point name will not turn it into a standalone program.
For a conventional application whose entry class is known, you can launch without editing its manifest. If app.jar sits beside a lib directory containing the required dependency JARs, use this on macOS or Linux:
java -cp "app.jar:lib/*" com.example.Main
On Windows, use a semicolon between classpath entries:
java -cp "app.jar;lib/*" com.example.Main
Run from the directory containing app.jar and lib, and confirm that the application starts. The wildcard includes JARs directly inside lib; it does not search nested directories.
Do not combine this workaround with -jar. In JAR launch mode, Java ignores the ordinary user classpath settings; dependencies must be supplied through the executable distribution’s supported mechanism, such as manifest classpath entries or a framework launcher.
Modular Applications
A modular application can have a module-based launch path rather than a conventional executable-JAR entry point.
Inspect the module descriptor:
jar --describe-module --file app.jar
For a self-contained modular application whose module name is com.example.app and entry class is com.example.Main, launch it explicitly:
java --module-path app.jar --module com.example.app/com.example.Main
Replace both names with the actual module and class names. Confirm normal application startup.
This supplies the entry point explicitly without requiring a manifest main-class header. If the application has additional module dependencies, its module path must include them; a supplied modular distribution or launcher is preferable to guessing that layout.
Verify the Fix and Keep It From Returning
Check the packaged result, not just the source configuration:
- Inspect the generated artifact. For an ordinary JAR launched with java -jar, confirm that Main-Class names the intended entry-point class and that its package path matches the class entry in the archive—for example, com.example.Main must be packaged as com/example/Main.class.
- Test outside the IDE. IDE run configurations can hide missing manifest settings and dependency packaging.
- Distinguish follow-on errors. “Main method not found” indicates an unsuitable entry class or method.
ClassNotFoundExceptionandNoClassDefFoundErrorpoint toward class-loading problems.UnsupportedClassVersionErrorpoints toward a Java-version mismatch. - Preserve the build configuration. Commit the manifest file or build-tool changes to version control rather than relying on a patched binary.
- Test the actual distribution. If users receive a JAR plus libraries or launch scripts, verify that complete package.
Rebuild from the saved configuration and launch the newly generated artifact. That final test confirms the fix survives packaging rather than working only on one manually edited file.
Frequently Asked Questions
Does Quoting the JAR Filename Cause This Error?
No. Double quotes around a filename are valid and are needed when its path contains spaces. Removing quotes does not add a missing entry point to the archive.
Does the Entry Class Have to Contain “Main” in Its Name?
No, the class can have any valid Java name. For the conventional entry-point form, the method must be named main and declared as public static void main(String[] args). Searching only for class filenames containing “main” can therefore miss the correct startup class.
Why Does the JAR Run on Another Computer but Not Mine?
The other computer may be using a launch script, shortcut, IDE configuration, or explicit-class launch instead of direct JAR execution. It may also have a different build of the archive. Compare the exact JAR file and launch method before modifying anything; changing computers does not add missing manifest metadata to an identical archive.
Why does hi.jar or input.jar still report no main manifest attribute after you create a manifest?
The JAR filename does not determine whether Java can launch it. When you use java -jar, the exact archive must be executable and contain a manifest with a Main-Class attribute; creating a separate manifest text file is not enough unless the packaging process puts it into that JAR.
