The fastest way to run a jar file

To run a jar file, open your command line or terminal, navigate to the folder where the jar file is stored, and type java -jar filename.jar (replacing "filename" with the actual name of your jar file). Press Enter. If Java is installed on your computer and the jar file is set up correctly, the program will start.

That command tells your computer to use Java to open and run the jar file. A jar file is a compressed archive — similar to a .zip file — that contains Java code and everything the program needs to run. Your computer needs Java installed to open it, and you need to run it from the command line rather than by double-clicking, because jar files don't have a default "open with" program the way other files do.

Key Takeaways

  • You must have Java installed on your computer; if the jar file won't run, check that Java is present and up to date.
  • The command java -jar filename.jar works only when you are in the same folder as the jar file, or when you type the full path to the file.
  • Some jar files need extra memory or settings to run properly, which you add to the command using flags like -Xmx1024m.
  • If the jar file opens a window and then closes immediately, the program likely crashed; check for error messages or a log file in the same folder.

Check that Java is installed

Before you try to run a jar file, confirm that Java is on your computer. Open your command line or terminal and type java -version, then press Enter. If Java is installed, you will see a version number. If you see "command not found" or "java is not recognized", Java is not installed or not set up correctly.

You can download Java from oracle.com (the official source) or from openjdk.java.net (the open-source version). Both work for running jar files. Install whichever version the jar file's instructions recommend, or use the latest version if no preference is stated. After installation, restart your command line and try java -version again.

Navigate to the jar file's folder

Open your command line or terminal. Type cd followed by a space and the path to the folder containing your jar file. For example, if the jar file is on your Desktop, type cd Desktop on Mac or Linux, or cd Desktop on Windows (the path format is the same in modern Windows terminals). Press Enter.

If the folder path has spaces in it — like "My Documents" — wrap the path in quotes: cd "My Documents". Once you are in the correct folder, type ls (Mac and Linux) or dir (Windows) and press Enter. You should see your jar file listed. If you don't see it, you are in the wrong folder; use cd .. to go up one level and try again.

Run the jar file with the basic command

Type java -jar filename.jar and press Enter, replacing "filename" with the actual name of your jar file. For example, if your jar file is called "MyApp.jar", type java -jar MyApp.jar. The program will start if everything is set up correctly.

If the jar file opens a window, it will stay open in your terminal. If it is a command-line program, output will print to your terminal. To stop the program, press Ctrl+C. If nothing happens or you see an error message, move to the next section.

Troubleshoot if the jar file won't run

If you see an error like "no main manifest attribute", the jar file is not set up to run as a standalone program. Some jar files are libraries meant to be used by other programs, not run directly. Check the jar file's documentation or the website where you downloaded it to see if it is meant to be run this way.

If the jar file opens a window and closes immediately without showing an error, the program likely crashed. Look in the same folder as the jar file for a log file (usually named something like "error.log" or "debug.log"). Open it with a text editor to see what went wrong. If there is no log file, try running the jar file again and watch the terminal window carefully for error messages before it closes.

If you see "Exception in thread" or "OutOfMemoryError", the program needs more memory than your computer is giving it. Try running it with java -Xmx1024m -jar filename.jar. The -Xmx1024m part tells Java to use up to 1024 megabytes of memory. If it still fails, increase the number: try 2048m or 4096m.

Run a jar file from a different folder

If you don't want to navigate to the jar file's folder, you can run it from anywhere by typing the full path. On Mac and Linux, type java -jar /full/path/to/filename.jar. On Windows, type java -jar C:\full\path\to\filename.jar (use backslashes instead of forward slashes).

The full path starts from the root of your drive. If you are not sure what the full path is, navigate to the folder in your file manager, look at the address bar, and copy the path from there. Then paste it into your terminal command.

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 the file is set up correctly. On others, it will open the file in an archive manager instead. The command line method always works, so that is the most reliable approach.

What if the jar file needs command-line arguments?

Add the arguments after the jar filename. For example, java -jar filename.jar argument1 argument2. Check the jar file's documentation to see what arguments it accepts and in what order.

Does the jar file have to be in the same folder as Java?

No. As long as Java is installed on your computer and added to your system path (which happens automatically during installation), you can run a jar file from any folder. The jar file and Java do not need to be in the same location.

Why does the terminal stay open after the jar file finishes?

On Windows, the terminal window may stay open after the program exits so you can see any final messages. On Mac and Linux, the terminal usually closes automatically. If you want to keep the window open to read messages, you can add a pause command, but this is not necessary for the jar file to run correctly.

Can I run a jar file on a Mac if it was made for Windows?

Yes, as long as Java is installed. Jar files are platform-independent — the same jar file runs on Windows, Mac, and Linux. The only requirement is that Java is present on your computer.