Question
How to Fix "No Main Manifest Attribute" in a JAR File (Java)
Question
I installed an application packaged as a JAR file, but when I try to run it, nothing happens. When I execute it from the command line with:
java -jar app.jar
I get this error:
no main manifest attribute, in app.jar
If I had built the program myself, I would know to add a Main-Class entry to the manifest file. But this JAR came from an existing application, so I do not control how it was packaged.
I also tried extracting the JAR and searching for the main class, but there are many classes and none of them obviously looks like the entry point.
If the program works on other systems, what does this error actually mean, and how can I determine the correct way to run this JAR?
Short Answer
By the end of this page, you will understand what the Java manifest file does, why java -jar requires a Main-Class, and why some JAR files are not meant to be launched directly. You will also learn how to inspect a JAR, check its manifest, identify whether it is a library or launcher component, and choose the correct way to run the application.
Concept
In Java, a JAR file is a ZIP-based archive that can contain compiled classes, resources, and metadata. One important piece of metadata is the manifest file, usually located at:
META-INF/MANIFEST.MF
When you run:
java -jar app.jar
Java does not search every class looking for a main method. Instead, it opens the JAR's manifest and looks for a special entry:
Main-Class: com.example.MyApp
If that entry is missing, Java cannot know which class to start, so it prints:
no main manifest attribute
Why this matters
This error does not always mean the application is broken. It often means one of these things:
- the JAR is a library, not a standalone application
- the JAR is only one part of a larger application
- the application is normally started by a script, launcher, IDE, installer, or wrapper
- the JAR was packaged incorrectly
- you are trying to run the wrong JAR in a folder containing several JARs
In real Java projects, not every JAR is executable. Many JARs are meant to be placed on the classpath and used by another program.
Key point
java -jar somefile.jar only works when that JAR contains a manifest with a valid entry. If it does not, you need to either:
Mental Model
Think of a JAR file like a box of parts.
- Some boxes are complete products with an instruction label on the outside.
- Some boxes are just components meant to be used inside a larger machine.
The manifest is like the label that says:
"Start here: use this class first."
When you use java -jar, Java reads that label.
- If the label exists, Java knows where to begin.
- If the label is missing, Java sees a box full of parts but has no instructions for which part to start with.
So the problem is usually not "Java cannot run classes." The problem is: Java was not told which class is the starting point.
Syntax and Examples
The two most common ways to run Java code are:
1. Run a JAR that has a manifest entry
java -jar app.jar
This requires a manifest like:
Main-Class: com.example.App
2. Run a class directly by naming it
java -cp app.jar com.example.App
This does not require a Main-Class in the manifest. But it only works if:
- you know the fully qualified class name
- that class has a valid
public static void main(String[] args)method
Example of a valid Java entry point
public class App {
public static void main(String[] args) {
System.out.println("Application started");
}
}
If this class were packaged into a JAR, the manifest would need:
Main-Class: App
Or, if it were in a package:
Step by Step Execution
Consider this command:
java -jar app.jar
Here is what Java does step by step:
Example scenario
Assume app.jar contains many .class files and resources.
Step 1: Java opens the JAR
Java treats the JAR as an archive and reads its metadata.
Step 2: Java looks for the manifest
It checks for:
META-INF/MANIFEST.MF
Step 3: Java searches for Main-Class
It expects a line like:
Main-Class: com.example.App
Step 4: If found, Java loads that class
Java then loads com.example.App and looks for:
public static void main(String[] args)
Step 5: The program starts
If the class exists and the main method is valid, execution begins.
Real World Use Cases
This concept appears often in real Java work.
Desktop applications
A desktop app may include several JARs:
- one launcher JAR
- multiple library JARs
- native dependencies
- shell or batch scripts to start everything correctly
If you run the wrong JAR directly, you may get the manifest error.
Framework-generated applications
Some build tools generate:
- executable JARs
- thin JARs
- library JARs
- test JARs
Only some of them are meant to be started with java -jar.
Server applications
A server app might be started with a script like:
./start.sh
That script may set:
- the classpath n- JVM options
- environment variables
- config locations
- the actual main class
Running a single JAR manually can fail even though the app itself is valid.
Libraries from package folders
If you downloaded a JAR from a lib/ directory, it is probably a dependency, not a runnable application.
Installer-created apps
Some installers place launchers in system-specific formats and the JAR is only an internal component. On another machine the application may appear to "run fine" because a wrapper script or executable is starting it properly.
Real Codebase Usage
In real projects, developers usually handle application startup in more structured ways.
Common patterns
Executable JAR packaging
Build tools such as Maven or Gradle are configured to write a Main-Class into the manifest for runnable applications.
Wrapper scripts
Projects often provide:
.shfiles on Linux/macOS.bator.cmdfiles on Windows
These scripts avoid startup mistakes by setting the correct classpath and options.
Bootstrap classes
Many applications do not start in the obvious business class. Instead they use a small bootstrap class that:
- validates environment variables
- loads configuration
- sets up logging
- handles errors early
- then starts the real app
Explicit classpath startup
Instead of relying on java -jar, developers may use:
java -cp "app.jar:lib/*" com.example.Main
or on Windows:
java -cp "app.jar;lib/*" com.example.Main
Common Mistakes
Beginners often make the following mistakes with JAR files.
1. Assuming every JAR is executable
A JAR is just a package format. It may be:
- a library
- a plugin
- a test artifact
- an executable app
Wrong assumption
java -jar commons-lang3.jar
This will fail because that JAR is a library, not an application.
2. Looking for a class named Main
The entry point class can have any name.
Wrong assumption
Main.classmust exist- the file name must include the word
main
Neither is required.
3. Confusing -jar with -cp
These are different startup modes.
Using -jar
java -jar app.jar
- uses the manifest
- ignores your normal classpath expectations
- requires
Main-Class
Using
Comparisons
| Approach | How it works | Needs Main-Class in manifest? | Best used when |
|---|---|---|---|
java -jar app.jar | Java reads the JAR manifest and starts the declared class | Yes | The JAR is packaged as a standalone executable |
java -cp app.jar com.example.App | You provide the classpath and main class manually | No | You know the main class and need direct control |
Startup script (start.sh, .bat) | Script sets options, classpath, env vars, and main class | No, not necessarily | The app has multiple dependencies or startup requirements |
| Double-clicking a launcher | OS or wrapper starts the app for you | Depends on packaging | End-user desktop apps |
Cheat Sheet
Quick reference
Run an executable JAR
java -jar app.jar
Requires manifest entry:
Main-Class: com.example.App
Run by naming the class directly
java -cp app.jar com.example.App
Inspect JAR contents
jar tf app.jar
Extract only the manifest
jar xf app.jar META-INF/MANIFEST.MF
What the error means
no main manifest attribute
Meaning:
- the JAR has no
Main-Classentry - or it is not meant to be run with
java -jar
Things to check
- Is this the correct JAR?
- Is there a
META-INF/MANIFEST.MFfile? - Does it contain
Main-Class:? - Is there a startup script like or ?
FAQ
Why does Java say "no main manifest attribute"?
Because java -jar looked inside the JAR manifest and did not find a Main-Class entry telling it which class to run.
Can a JAR work without a manifest?
Yes. A JAR can still be used as a library on the classpath. It just cannot be launched with java -jar unless the manifest includes the correct entry point.
Can I run the JAR if I know the main class?
Yes. You can use:
java -cp app.jar com.example.MainClass
You may also need additional dependency JARs on the classpath.
Why does the app run on another computer?
That system may be using a launcher script, wrapper executable, shortcut, or a different JAR file that sets the correct startup class and dependencies.
How can I find the main class inside a JAR?
First inspect META-INF/MANIFEST.MF. If there is no Main-Class, search the compiled classes for a method with this signature:
public static void main(String[] args)
Can I just add a Main-Class to the manifest myself?
Mini Project
Description
Build a small Java application and package it in two different ways so you can see the difference between a runnable JAR and a non-runnable JAR. This demonstrates exactly why the no main manifest attribute error happens and how to inspect the archive to confirm it.
Goal
Create one JAR that fails with java -jar and another that runs successfully after adding the correct Main-Class manifest entry.
Requirements
- Create a simple Java class with a
public static void main(String[] args)method. - Compile the class and package it into a JAR without a
Main-Classentry. - Verify that running it with
java -jarproduces the manifest error. - Create a manifest file that includes the correct
Main-Classvalue. - Build a second JAR using that manifest and run it successfully.
Keep learning
Related questions
Avoiding Java Code in JSP with JSP 2: EL and JSTL Explained
Learn how to avoid Java scriptlets in JSP 2 using Expression Language and JSTL, with examples, best practices, and common mistakes.
Choosing a @NotNull Annotation in Java: Validation vs Static Analysis
Learn how Java @NotNull annotations differ, when to use each one, and how to choose between validation, IDE hints, and static analysis tools.
Convert a Java Stack Trace to a String
Learn how to convert a Java exception stack trace to a string using StringWriter and PrintWriter, with examples and common mistakes.