The simplest way to run a JAR file

A JAR file (Java Archive) is a compressed folder that holds Java code and resources. To run one, you need Java installed on your computer, then you open a command line and type a single command. The file runs in a window or terminal — it does not install anything or change your system settings.

The command is always the same shape: java -jar filename.jar. You type this into Command Prompt on Windows, Terminal on Mac, or any terminal on Linux. The computer finds the JAR file in your current folder and runs it.

If the JAR file is in a different folder, you either navigate to that folder first or type the full path to the file. Most people keep the JAR file on their Desktop or in a Downloads folder, navigate there in the terminal, and run it from there.

Key Takeaways

  • You must have Java installed before you can run any JAR file — check by typing java -version in your terminal.
  • The command to run a JAR file is java -jar filename.jar, typed into Command Prompt, Terminal, or a Linux terminal.
  • Navigate to the folder where the JAR file sits before running the command, or type the full path to the file.
  • Some JAR files are designed to run in the background; others open a window or print output to the terminal.

Check whether Java is installed

Before you try to run a JAR file, open your terminal and type java -version. If Java is installed, you will see a version number — something like "java version 17.0.1" or "openjdk version 21". If you see "command not found" or "is not recognized", Java is not installed or not in your system path.

If Java is not installed, download it from Oracle's website (the official Java Runtime Environment) or use a free version like OpenJDK. Installation is straightforward on all three operating systems — download the installer, run it, and follow the prompts. After installation, restart your terminal and run java -version again to confirm it worked.

Navigate to the JAR file's location on Windows

Open Command Prompt by pressing Windows key + R, typing cmd, and pressing Enter. You will see a black window with a blinking cursor. By default, you are in your user folder (usually C:\Users\YourName).

If your JAR file is on your Desktop, type cd Desktop and press Enter. If it is in Downloads, type cd Downloads. If it is somewhere else, type cd followed by the path — for example, cd C:\Users\YourName\Documents\MyProgram. After you press Enter, you should see the folder path in the prompt.

To see what files are in the current folder, type dir and press Enter. You will see a list of all files and folders. Find your JAR file in that list to confirm you are in the right place.

Navigate to the JAR file's location on Mac and Linux

Open Terminal (on Mac, press Command + Space, type "Terminal", and press Enter; on Linux, right-click the desktop or use your application menu). You will see a prompt ending with a dollar sign or percent sign.

Type cd followed by the path to your folder. For example, if the JAR file is on your Desktop, type cd ~/Desktop and press Enter. If it is in your Documents folder, type cd ~/Documents. The tilde (~) is a shortcut for your home folder.

To see what files are in the current folder, type ls and press Enter. You will see a list of all files and folders. Find your JAR file in that list to confirm you are in the right place.

Run the JAR file

Once you are in the folder where the JAR file sits, type java -jar filename.jar and press Enter. Replace "filename" with the actual name of your JAR file — for example, java -jar MyApp.jar or java -jar minecraft-launcher.jar. The name must match exactly, including uppercase and lowercase letters.

If the file name has spaces in it, put the whole name in quotes: java -jar "My App.jar". After you press Enter, the program starts. Some JAR files open a new window; others print text to the terminal. Some run silently in the background.

If you see an error like "no main manifest attribute", the JAR file is not set up to run directly from the command line. This is not a problem with your computer — it means the file is a library or tool that another program uses, not a standalone application.

Run a JAR file from any folder without navigating

If you do not want to navigate to the folder each time, type the full path to the JAR file instead. On Windows, this looks like java -jar C:\Users\YourName\Desktop\MyApp.jar. On Mac or Linux, it looks like java -jar ~/Desktop/MyApp.jar or java -jar /home/username/Desktop/MyApp.jar.

You can type this command from any folder — the terminal will find the JAR file wherever it is. If the path has spaces, put the whole path in quotes: java -jar "C:\Users\Your Name\Desktop\My App.jar" on Windows or java -jar "~/Desktop/My App.jar" on Mac and Linux.

Frequently Asked Questions

What does "command not found" mean when I try to run java -version?

It means Java is not installed or your computer cannot find it in the system path. Download and install Java from Oracle's website or use OpenJDK, then restart your terminal and try again. After installation, java -version should show a version number.

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

On Windows and Mac, yes — if Java is installed and the JAR file is set up to run that way, double-clicking it will start the program. On Linux, this usually does not work. If double-clicking does not work, the command-line method always will.

Why does my JAR file close immediately after it starts?

The program may have finished running or encountered an error. Run it from the terminal instead of double-clicking so you can see any error messages. Type java -jar filename.jar and watch the terminal output to see what happened.

Can I give a JAR file more memory to use?

Yes. Type java -Xmx2G -jar filename.jar to give it 2 gigabytes of memory (change the number as needed). This is useful for large programs that run slowly or crash with "out of memory" errors.

What if the JAR file needs command-line arguments?

Add them after the file name: java -jar filename.jar argument1 argument2. The documentation for the JAR file will tell you what arguments it accepts. Arguments are separated by spaces; if an argument contains spaces, put it in quotes.