To execute a JAR file, use the command line to run java -jar yourfile.jar after installing Java.
A JAR file is a compressed archive that packages Java classes—it won’t open like a regular program until you give it the right command. The standard method works the same on Windows, macOS, and Linux: install the Java Runtime, open a terminal, and type one short command. This guide walks you through the exact steps, explains the double-click option, and shows you how to fix the most common roadblocks.
What Do You Need Before Running a JAR File?
You need two things: the Java Runtime Environment (JRE) installed on your system and a JAR file that was packaged as an executable application (one with a Main-Class entry in its manifest).
- Install Java – Download the latest JRE from
java.comor install it through your package manager. On Ubuntu usesudo apt install default-jre; on Fedora usesudo dnf install java-latest-openjdk; on Arch usesudo pacman -S jre-openjdk. - Verify the install – Open a terminal and run
java -version. If you see version info, Java is ready. If you get “command not found,” Java isn’t on your PATH—reinstall or add thebinfolder manually. - Check the JAR is runnable – Only JARs with a manifest that sets
Main-Classwill execute withjava -jar. Library JARs (like those used for dependencies) won’t launch an application.
How to Execute a JAR File from the Command Line
The reliable cross‑platform method is a single command. Oracle’s official documentation recommends this approach, and it works regardless of your operating system.
- Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux).
- Navigate to the folder containing the JAR file, or specify its full path. For example, if the file is in your Downloads folder:
cd Downloads
or use the path directly:java -jar C:\Users\you\Downloads\app.jar. - Type:
java -jar yourfile.jar(replace yourfile.jar with the actual file name). - Press Enter. If the JAR is executable, the program’s interface should appear. If nothing happens, you may need to check the manifest or ensure the JAR isn’t a library.
Oracle stresses that the -jar flag only works when the manifest contains a Main-Class entry. For the full official steps, see Oracle’s tutorial for running JAR files.
When the command runs correctly, the program’s GUI or console output should start immediately. If you see a “no main manifest attribute” error, the JAR wasn’t packaged as an application.
Running a JAR File by Double‑Clicking
You can also launch a JAR by double‑clicking it, provided your OS is set to associate .jar files with Java. This doesn’t always work out of the box, especially on Windows.
- Windows: Right‑click the JAR, choose Open with > Java(TM) Platform SE binary. If Java isn’t listed, run the Java installer again or create a
.batfile withjava -jar yourfile.jarand double‑click that instead. - macOS: The system may open the JAR with Archive Utility (because JARs are ZIP files). Change the default to Java Jar Launcher via Get Info > Open with.
- Linux: Most desktop environments let you right‑click the file and select Open with > OpenJDK Java Runtime. If that option is missing, use the terminal method.
Double‑click is convenient but less reliable—the command line is the authoritative, problem‑free approach.
| Method / Platform | Command or Steps | Notes |
|---|---|---|
| Command Line – Windows | java -jar app.jar (in Command Prompt) |
Add full path if file is elsewhere, e.g., java -jar C:\Users\me\app.jar |
| Command Line – macOS | java -jar app.jar (in Terminal) |
Same syntax; navigate to the JAR’s folder first |
| Command Line – Linux (Ubuntu/Debian) | java -jar app.jar |
Install Java with sudo apt install default-jre before running |
| Command Line – Linux (Fedora/RHEL) | java -jar app.jar |
Install with sudo dnf install java-latest-openjdk |
| Double‑Click – Windows | Right‑click > Open with > Java | May need to repair file association or use a .bat wrapper |
| Double‑Click – macOS | Right‑click > Open with > Java Jar Launcher | Change default in Get Info to avoid ZIP extraction |
| Double‑Click – Linux | Right‑click > Open with > OpenJDK Runtime | Not always available; terminal is more dependable |
Common Errors: Why Won’t My JAR File Execute?
Most problems fall into a handful of categories. The table below shows the typical causes and their fixes.
| Error / Symptom | Cause | Fix |
|---|---|---|
| “Java is not recognized” / “command not found” | Java not installed or not on PATH | Install JRE and ensure the bin folder is in your system PATH |
| “no main manifest attribute” | JAR lacks a Main-Class entry in its manifest |
It’s a library JAR, not an application; use it as a dependency instead |
| “Unable to access jarfile” | Wrong path or filename | Check the spelling and location; use the full path if needed |
| Double‑click opens an archive program | File association set to unzip instead of run | Change default program to Java runtime; use command line as fallback |
| “Error: Could not find or load main class” | Manifest’s Main-Class value is incorrect or class is missing |
Verify the class name in the manifest, or repackage the JAR |
| Nothing happens after command | JAR might be a headless server app or require arguments | Check documentation; some JARs require parameters like java -jar server.jar nogui |
Final Checklist for Running a JAR File
- Confirm Java is installed and accessible from the terminal (
java -version). - Verify the JAR is an executable application (contains a manifest with
Main-Class). - Open a terminal and navigate to the JAR’s folder (or specify the full path).
- Run
java -jar yourfile.jar. - If the program doesn’t start, check the error message against the table above.
That’s it. The command‑line method is the simplest, most universal way to execute any runnable JAR file on any operating system.
References & Sources
- Oracle. “Running JAR-Packaged Software.” Official tutorial with the standard command and manifest requirements.
- Oracle. “JAR File Overview.” Details on the JAR format and manifest file specifications.
