How to Run a JAR File on Windows, Mac, and Linux

JAR files are everywhere in the Java ecosystem — they package applications, libraries, and tools into a single portable archive. But unlike a .exe on Windows or an .app on macOS, double-clicking a JAR file doesn't always "just work." Understanding why — and how to fix it — depends on a few key factors about your system.

What Is a JAR File?

JAR stands for Java ARchive. It's essentially a ZIP file containing compiled Java class files, metadata, and sometimes executable instructions. JAR files are used to distribute Java applications, plugins, and libraries across any operating system.

The critical dependency: JAR files require a Java Runtime Environment (JRE) or Java Development Kit (JDK) to run. Without Java installed on your system, no method of launching a JAR file will work.

Step 1 — Verify Java Is Installed

Before anything else, check whether Java is installed and which version you have.

Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and type:

java -version 

If Java is installed, you'll see output like:

java version "17.0.8" 2023-07-18 

If you get an error like java is not recognized or command not found, Java isn't installed or isn't added to your system's PATH. You'll need to install a JRE or JDK — the Java SE Runtime Environment from Oracle and the OpenJDK builds are both widely used options.

How to Run a JAR File from the Command Line

The most reliable method across all operating systems is the command line.

java -jar yourfile.jar 

Navigate to the folder containing the JAR first, or include the full file path. This method works on Windows, macOS, and Linux without any additional configuration.

When the JAR Has Dependencies

Some JAR files rely on external libraries. If you see ClassNotFoundException or NoClassDefFoundError errors, the JAR likely expects other JAR files in a specific location. In these cases, you may need to specify a classpath:

java -cp yourfile.jar:lib/* com.example.MainClass 

On Windows, replace : with ; in the classpath separator.

Running a JAR File by Double-Clicking 🖱️

On many systems, you can run a JAR file by double-clicking it — but only if:

  • Java is installed
  • The JAR file has a manifest file that specifies a Main-Class entry point
  • Your OS has JAR files associated with the Java runtime
Operating SystemDouble-Click Behavior
WindowsWorks if Java is installed and file association is set
macOSMay prompt for security approval; Gatekeeper can block unsigned JARs
LinuxDepends on desktop environment and file manager settings

Windows File Association

If double-clicking opens the JAR as an archive instead of running it, the file association may be wrong. You can right-click the JAR, choose Open With, and select the Java Platform SE Binary (javaw.exe). The javaw.exe executable runs Java applications without opening a command prompt window, while java.exe opens one — useful for apps that display console output.

macOS Security Considerations

macOS Gatekeeper can prevent unsigned JAR files from running. You may need to go to System Settings → Privacy & Security and explicitly allow the file to open. This is a common friction point for users running JAR-distributed tools or indie software.

JAR Files That Are Libraries, Not Applications

Not every JAR is meant to be executed directly. Library JARs contain code for developers to include in their own projects — they have no Main-Class defined. Attempting to run one with java -jar will return:

no main manifest attribute, in yourfile.jar 

This isn't an error you can fix by changing your Java version or settings — the JAR simply wasn't built to run standalone.

Variables That Affect How This Works for You ⚙️

Several factors determine which approach applies to your situation:

  • Java version compatibility — A JAR compiled for Java 17 won't run on a Java 8 runtime. The error message will usually indicate the version mismatch.
  • Operating system and version — macOS security policies, Linux desktop environments, and Windows file associations all handle JARs differently.
  • Whether the JAR is executable — Only JARs with a properly defined Main-Class in their manifest can be launched with java -jar.
  • Dependencies — Standalone JARs (sometimes called "fat JARs" or "uber JARs") bundle everything they need. Others expect libraries to be present separately.
  • Technical comfort level — The command-line method is universal but requires basic terminal familiarity. GUI-based approaches are easier but less reliable across setups.

Troubleshooting Common Errors

"java is not recognized" — Java isn't installed or the PATH environment variable isn't configured. Reinstall Java and ensure it's added to PATH during setup.

"no main manifest attribute" — The JAR is a library, not a standalone application. Check the project's documentation for the correct run command.

"UnsupportedClassVersionError" — Your Java runtime is older than the version used to compile the JAR. Update your JRE or JDK. 🔧

JAR opens as a zip archive — File association is wrong. Reassociate .jar files with javaw.exe on Windows or configure your file manager on Linux.

The Part That Depends on Your Setup

Whether you run the JAR via command line, double-click, or a script wrapper — and whether it succeeds — comes down to your specific Java version, OS configuration, and what the JAR was built to do. A JAR that runs perfectly on one machine might fail silently on another due to a mismatched Java version or missing dependency folder. The command java -jar is always the safest starting point, but what you see after running it tells you everything about what your particular environment needs next.