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 Main-Class entry. If it does not, you need to either:
- run a different JAR
- run the program using its documented startup script
- specify the main class manually with
-cp - or fix the packaging if you control the build
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:
package com.example;
public class App {
public static void main(String[] args) {
System.out.println("Application started");
}
}
Then the manifest would need:
Main-Class: com.example.App
How to inspect the manifest
You can list the contents of the JAR:
jar tf app.jar
You can extract the manifest:
jar xf app.jar META-INF/MANIFEST.MF
Then open:
META-INF/MANIFEST.MF
If you do not see Main-Class, then java -jar cannot launch that JAR directly.
Example manifest
Manifest-Version: 1.0
Main-Class: com.example.App
That is the metadata Java needs for java -jar.
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.
What happens in your error case
If the manifest looks like this:
Manifest-Version: 1.0
Created-By: SomeTool
then Java reaches Step 3 and finds no Main-Class entry.
At that point it stops and prints:
no main manifest attribute, in app.jar
Important detail
Java does not scan every class in the archive looking for a main() method when using -jar.
That is why extracting the JAR and looking through class names is usually not enough. A main class can be named anything, such as:
LauncherBootstrapStartAppClient
It does not have to contain the word main in the filename or class name.
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
This is common when the application depends on multiple JAR files.
Validation and early failure
Startup code often checks required configuration first and exits with a clear error. That is one reason many projects prefer a launcher class or script rather than expecting users to run internal JARs manually.
What to do in a real codebase
If you are debugging a third-party app:
- inspect the JAR manifest
- look for startup scripts in the installation folder
- check documentation or README files
- identify whether the JAR is a library or an executable
- if needed, search classes for a real
mainmethod instead of relying on names alone
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 -cp
java -cp app.jar com.example.App
- you provide the main class yourself
- useful when the manifest is missing
4. Editing the JAR without understanding dependencies
Even if you add a Main-Class, the application may still fail if:
- dependencies are missing
- the wrong class is chosen
- startup scripts were supposed to configure the environment
5. Searching by filename instead of method signature
A class may contain a valid entry point even if its name is not obvious.
The real thing to search for is:
public static void main(String[] args)
6. Running the wrong file from the installation directory
Some folders contain many JARs, for example:
app.jarapp-core.jarlauncher.jarlib/*.jar
Only one of them may be intended for direct execution.
Broken example: assuming class names tell you everything
com/example/Engine.class
com/example/Bootstrap.class
com/example/UiClient.class
A beginner might ignore these because none is named Main, but Bootstrap could easily contain the entry point.
How to avoid these mistakes
- inspect
META-INF/MANIFEST.MF - check for launch scripts
- search for
main(String[] args)if necessary - verify whether the JAR is documented as executable
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 |
Executable JAR vs library JAR
| Type | Contains classes | Has manifest | Runnable with java -jar | Typical purpose |
|---|---|---|---|---|
| Executable JAR | Yes | Usually includes Main-Class | Yes | Start an application |
| Library JAR | Yes | May have a manifest, but no Main-Class | Usually no | Provide reusable code to other apps |
-jar vs -cp
| Feature | -jar | -cp |
|---|---|---|
| Main class source | Manifest | Command line |
| Easy for end users | Yes | Less so |
| Flexible for debugging | Less | More |
| Common for packaged apps | Yes | Yes, especially in scripts |
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
run.shorapp.bat? - Is this actually a library JAR?
Important rule
java -jar does not search all classes for main().
If you know the main class
java -cp "app.jar:lib/*" com.example.Main
On Windows:
java -cp "app.jar;lib/*" com.example.Main
Common edge case
A program may work on another system because that system launches it using:
- a wrapper executable
- a shell script
- a batch file
- an IDE configuration
- an installer-created shortcut
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?
Only if you understand how the application is packaged. Adding it may not be enough if the app also depends on other JARs, startup parameters, or environment configuration.
Does the main class have to be named Main?
No. The class can have any valid name. What matters is that it contains a proper main method.
Is this always a packaging bug?
No. Often it simply means the file is not intended to be run directly as an executable JAR.
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
Add External JAR Files to an IntelliJ IDEA Java Project
Learn how to add external JAR dependencies to an IntelliJ IDEA Java project using module libraries, and when to use Maven or Gradle instead.
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.
Call a Method After a Delay in Android Java
Learn how to run Java code after a delay in Android using Handler.postDelayed, manage the main thread, and cancel callbacks safely.