The basic command to run a JAR file
To run a JAR file, open your command line or terminal and type java -jar filename.jar, replacing "filename" with the actual name of your JAR file. Press Enter. That's the core of it — Java looks for the file in your current directory, reads the instructions inside, and starts the program.
The reason this works is that a JAR file is really a compressed folder containing Java code and a manifest file that tells Java which part of the code to start first. When you run the command, Java unpacks it in memory and executes whatever the manifest points to.
If you get an error saying "java is not recognized" or "command not found", Java is not installed on your computer or not in your system's PATH. You'll need to install Java first — download it from oracle.com or use a package manager if you're on Linux or Mac.
Key Takeaways
- The command java -jar filename.jar runs a JAR file from your command line or terminal.
- You need Java installed on your computer, and the JAR file must have a manifest file that specifies which class contains the main method.
- If the JAR file needs more memory than Java allocates by default, use java -Xmx1024m -jar filename.jar to give it up to 1 gigabyte.
- Some JAR files are libraries meant to be used by other programs, not run directly — these will fail with an error about a missing main method.
- On Windows, you can double-click a JAR file to run it if Java is installed and associated with the .jar extension, though using the command line gives you more control.
Making sure Java is installed and accessible
Before you can run any JAR file, your computer needs Java installed. Check by opening your command line (cmd.exe on Windows, Terminal on Mac or Linux) and typing java -version. If Java is installed, you'll see a version number like "java version 17.0.1". If you see "command not found" or "is not recognized as an internal or external command", Java is not installed or not in your PATH.
To install Java, go to oracle.com/java/technologies/downloads and download the Java Development Kit (JDK) or Java Runtime Environment (JRE). The JRE is smaller and sufficient if you only want to run JAR files; the JDK includes tools for writing and compiling Java code. Follow the installer for your operating system. After installation, restart your command line and run java -version again to confirm it worked.
On Linux, you can often install Java through your package manager instead. On Ubuntu or Debian, run sudo apt install default-jre. On Fedora or Red Hat, run sudo dnf install java-latest-openjdk. This is faster than downloading from Oracle and keeps Java updated automatically.
Running a JAR file from the command line
Navigate to the folder where your JAR file is stored using the cd command. On Windows, if your file is on your Desktop, type cd Desktop. On Mac or Linux, type cd ~/Desktop. Then type java -jar filename.jar, replacing "filename" with the actual name. If the file is named "MyApp.jar", the command is java -jar MyApp.jar.
The program will start and print output to your command line window. If it's a graphical program, a window will open. If it's a background service or tool, it may run silently or print status messages. Leave the command line window open while the program runs — closing it will stop the program.
If you want to run the JAR file from a different folder without navigating to it first, type the full path: java -jar C:\Users\YourName\Desktop\MyApp.jar on Windows, or java -jar ~/Desktop/MyApp.jar on Mac and Linux. Use forward slashes even on Windows if you're using PowerShell or a Unix-like terminal.
Giving a JAR file more memory
Some JAR files need more memory than Java gives them by default. If a program crashes with an error like "OutOfMemoryError" or "heap space", you can increase the memory limit using the -Xmx flag. The command java -Xmx1024m -jar filename.jar gives the program up to 1 gigabyte of memory. Change 1024 to a different number if you want more or less — 512m is 512 megabytes, 2048m is 2 gigabytes.
Check how much memory your computer has before setting this value. On Windows, right-click "This PC" or "My Computer" and select Properties. On Mac, click the Apple menu, select "About This Mac", and look for "Memory". On Linux, run free -h in the terminal. Set -Xmx to less than your total memory, leaving room for the operating system and other programs.
You can also set a minimum memory allocation with -Xms. The command java -Xms512m -Xmx2048m -jar filename.jar starts the program with 512 megabytes and lets it grow up to 2 gigabytes as needed. This is useful for programs that need a lot of memory but don't need it all at startup.
Understanding JAR files that won't run
Not every JAR file is meant to be run directly. Some are libraries — collections of code that other programs use. If you try to run a library JAR and get an error like "no main manifest attribute", the JAR file doesn't have an entry point. This is normal and not a problem with your computer or Java installation.
To know whether a JAR file should run, check the documentation that came with it or the website where you found it. If it says "library" or "dependency", it's not meant to be executed on its own. If it says "application" or "executable", it should run with the java -jar command.
Some JAR files are meant to be run with additional arguments or configuration files. For example, java -jar app.jar --config settings.txt passes the file "settings.txt" to the program. Check the README or help documentation to see what arguments the program expects.
Running a JAR file by double-clicking on Windows or Mac
On Windows, if Java is installed and properly associated with .jar files, you can double-click a JAR file to run it. This opens a command line window, runs the program, and closes the window when the program exits. If double-clicking doesn't work, right-click the file, select "Open with", and choose Java or "Java Platform SE binary".
On Mac, double-clicking a JAR file may not work by default. Instead, open Terminal, drag the JAR file into the Terminal window (which pastes its path), type java -jar before the path, and press Enter. Alternatively, you can create a shell script that runs the JAR file and make it executable, though this is more advanced.
Double-clicking is convenient but gives you less control than the command line. You can't easily pass arguments to the program, adjust memory settings, or see detailed error messages. For troubleshooting or running programs with specific settings, use the command line method instead.
Frequently Asked Questions
What if I get a "file not found" error?
The JAR file is not in the folder where you're running the command. Check the exact filename and spelling — "MyApp.jar" is different from "myapp.jar" on Mac and Linux. Use ls (Mac and Linux) or dir (Windows) to list files in your current folder and confirm the name. If the file is in a different folder, either navigate to it with cd or use the full path.
Can I run a JAR file on a computer without Java installed?
No, Java must be installed. However, some programs bundle Java inside their installer, so the end user doesn't have to install it separately. If you're distributing a JAR file to others, you can use tools like Launch4j or jpackage to create a standalone executable that includes Java. This is beyond what most users need to do.
Why does my JAR file open in an archive manager instead of running?
Your computer is treating the JAR file as a compressed folder rather than an executable. This usually means Java is not installed or not associated with .jar files. Install Java, then on Windows, right-click a JAR file, select "Open with", and choose Java. On Mac, use the Terminal method instead.
How do I stop a JAR file that's running?
If it's running in a command line window, press Ctrl+C (or Cmd+C on Mac). If it opened a graphical window, close that window. If the program is running in the background and you can't find it, on Windows use Task Manager (Ctrl+Shift+Esc) to find and end the Java process, or on Mac use Activity Monitor to find and quit it.
Can I edit a JAR file to change how it runs?
JAR files are compressed archives, so you can open them with any archive tool and view or extract the files inside. However, editing the code requires recompiling it, which is a programming task beyond running a JAR file. If you need to modify a program, look for the source code or contact the developer.