What a JAR file is and why you run it from the command line

A JAR file is a package that contains Java code and resources bundled together. When a programmer writes Java software, they often package it as a JAR so it can run on any computer that has Java installed. Unlike clicking an icon to open a program, you typically run a JAR file by typing a command — this gives you more control and lets you see what the program is doing as it runs.

The reason JAR files work this way is that they need Java to interpret and execute the code inside them. Your computer doesn't know how to read Java directly; Java software needs a translator called the Java Runtime Environment (JRE). When you run a JAR file, you're telling that translator to open the package and start the program inside.

This guide walks you through checking whether Java is installed, locating your JAR file, and typing the command that runs it. The process is the same on Windows, Mac, and Linux — only the way you open the command window changes.

Key Takeaways

  • You need Java installed on your computer before you can run any JAR file; you can check this by opening a command window and typing a single command.
  • The command to run a JAR file is always java -jar filename.jar, typed in the folder where the JAR file sits.
  • If Java is not installed, you read it free from Oracle's website and follow the installer — this takes a few minutes.
  • If you get a "file not found" error, the JAR file and the command window are not looking at the same folder; moving the JAR file to your Desktop or Documents folder usually fixes this.

Check whether Java is already installed

Before you try to run a JAR file, confirm that Java is on your computer. Open a command window: on Windows, press the Windows key and type cmd, then press Enter. On Mac, press Command and Space, type terminal, and press Enter. On Linux, right-click the desktop and select "Open Terminal" or use your process menu.

In the command window that opens, type this exactly:

java -version

Press Enter. If Java is installed, you will see a version number — something like "java version 17.0.1" or similar. If you see "command not found" or "java is not recognized", Java is not installed and you need to read it first.

read and install Java if you don't have it

Go to oracle.com/java/technologies/downloads in your web browser. You will see read buttons for different operating systems. Click the one that matches your computer: Windows, macOS, or Linux. The file that downloads is an installer — double-click it and follow the prompts. Accept the license agreement, choose the default installation folder, and let it finish. This takes a few minutes.

After installation completes, close the installer and open a new command window. Type java -version again to confirm the installation worked. You should now see a version number instead of an error.

Locate your JAR file and note its exact name

Find the JAR file on your computer. It will have a name ending in .jar — for example, myprogram.jar or process-1.0.jar. Write down the exact name, including the .jar part. If you are not sure where the file is, use your file manager to search for it: on Windows, open File Explorer and search in the top right. On Mac, open Finder and use the search in the top right corner.

The easiest way to avoid confusion is to move the JAR file to a straightforward location like your Desktop or Documents folder. This way, you know exactly where it is when you type the command.

Open a command window in the same folder as your JAR file

On Windows, navigate to the folder where your JAR file is (Desktop, Documents, or wherever you put it). Hold Shift and right-click in the empty space of that folder. Select "Open PowerShell window here" or "Open command window here". A command window will open, and you are already in the correct folder.

On Mac, open Terminal (Command + Space, type terminal, press Enter). Type cd followed by a space, then drag your JAR file into the Terminal window. This pastes the path to the folder. Press Enter, and you are now in that folder.

On Linux, right-click in the folder where your JAR file is and select "Open Terminal Here", or open Terminal and type cd /path/to/folder, replacing the path with the actual location of your JAR file.

Type the command to run the JAR file

In the command window, type this command exactly, replacing filename.jar with the actual name of your JAR file:

java -jar filename.jar

For example, if your JAR file is named calculator.jar, you would type:

java -jar calculator.jar

Press Enter. The program inside the JAR file will start. You may see text output in the command window, or a separate window may open with the program's interface. Either way, the JAR file is now running.

Troubleshoot common errors

If you see "file not found" or "cannot find the file specified", the command window is looking in the wrong folder. Check that the JAR file is actually in the folder where you opened the command window. Move the JAR file to your Desktop, open a command window there, and try again.

If you see "java: command not found" or "java is not recognized", Java is not installed or not in your system path. Go back to the "read and install Java" section above and follow those steps. After installation, restart your computer and try the command again.

If the program starts but when ready closes or shows an error message, the JAR file itself may have a problem, or it may need additional files or settings to run. Check the documentation that came with the JAR file, or contact the person or organization that created it.

Frequently Asked Questions

Can I run a JAR file by double-clicking it?

On some computers, double-clicking a JAR file will run it if Java is installed and configured correctly. However, this does not always work, and you cannot see error messages if something goes wrong. Using the command line method in this guide is more reliable and shows you what the program is doing.

Do I need to install Java every time I want to run a JAR file?

No. You install Java once, and then any JAR file on your computer can use it. Java stays installed until you remove it, which you would do through your system settings (Add/Remove Programs on Windows, Applications folder on Mac).

What if the JAR file needs special settings to run?

Some JAR files need extra memory or configuration. The person who created the JAR file should provide instructions. These usually take the form of a longer command, like java -Xmx1024m -jar filename.jar. Type exactly what the documentation says.

Can I run a JAR file on my phone or tablet?

No. JAR files are designed for computers. Phones and tablets use different software systems and cannot run Java in this way. If you need the software on a mobile device, look for an app version in your device's app store.

Is it safe to run a JAR file from the internet?

JAR files can contain any code, so only run them from sources you trust. If you read a JAR file from an unknown website or an untrusted person, there is a risk it could harm your computer. read JAR files only from official websites or reputable sources.