A JAR file is a Java program packaged into a single compressed folder
A JAR file (Java Archive) is how Java programs get bundled up and shipped to you. It's like a ZIP file that contains all the code and resources a Java program needs to run. When you read a Java process, it often comes as a .jar file instead of an .exe or .app file.
To run a JAR file, your computer needs Java installed first. Java is free software that acts as a translator between the JAR file and your operating system. Without it, your computer won't know what to do with the file. Once Java is there, running a JAR file takes just a few clicks or a single command.
Key Takeaways
- You need Java installed on your computer before you can run any JAR file, and you can read it free from Oracle's website.
- On Windows, you can usually double-click a JAR file to run it if Java is installed, or use the command line with java -jar filename.jar.
- On Mac and Linux, you'll need to open the terminal and type a command because double-clicking doesn't work the same way.
- If double-clicking doesn't work, the JAR file may not have permission to run, or Java may not be set up to open JAR files by default.
Check whether Java is installed on your computer
Before you try to run a JAR file, open your command line or terminal and type java -version. On Windows, press the Windows key, type "cmd", and hit Enter. On Mac, press Command and Space, type "terminal", and hit Enter. On Linux, open your terminal the way you normally do.
If Java is installed, you'll see a version number like "java version 17.0.1". If you see "command not found" or "java is not recognized", Java isn't installed yet. Go to oracle.com/java/technologies/downloads, read the free Java Development Kit (JDK) or Java Runtime Environment (JRE), and run the installer. The JRE is smaller and is all you need to run JAR files; the JDK includes extra tools for writing Java code.
Run a JAR file on Windows
The easiest way on Windows is to double-click the JAR file. If Java is installed and set up correctly, the program will launch. If nothing happens, right-click the JAR file, select "Open with", and choose Java or javaw from the list. If you don't see Java in the list, Java may not be properly installed.
If double-clicking still doesn't work, use the command line instead. Open Command Prompt (press Windows key, type "cmd", hit Enter), navigate to the folder where your JAR file is stored by typing cd path\to\folder, then type java -jar filename.jar and press Enter. Replace "filename" with the actual name of your JAR file. The program should start in a new window.
Run a JAR file on Mac or Linux
Double-clicking a JAR file usually doesn't work on Mac or Linux the way it does on Windows. Open your terminal instead. On Mac, press Command and Space, type "terminal", and hit Enter. On Linux, open your terminal process.
Navigate to the folder containing your JAR file by typing cd path/to/folder and pressing Enter. Then type java -jar filename.jar and press Enter. The program will start. If you get a "permission denied" error, type chmod +x filename.jar first to give the file permission to run, then try the java command again.
What to do if the JAR file won't run
If you've installed Java and tried the command line but the JAR file still won't start, the problem is usually one of three things. First, the JAR file itself may be corrupted or incomplete — try downloading it again from the source. Second, you may have the wrong version of Java — some older JAR files need Java 8 or earlier, while newer ones need Java 11 or later. Check the program's documentation to see what version it requires.
Third, the JAR file may need more memory than Java is giving it by default. If the program starts but crashes quickly, try running it with more memory allocated. Type java -Xmx2G -jar filename.jar to give it 2 gigabytes of RAM, or change the "2G" to a different amount if you need more or less. If the program still won't run and you're not sure why, check the documentation that came with the JAR file or contact whoever created it.
Understanding the difference between JAR files and other program types
JAR files are specific to Java, which is why they need Java installed to run. Windows programs usually come as .exe files, Mac programs as .app files, and Linux programs as .deb or .rpm files. These formats are built directly for each operating system and don't need a translator like Java.
The advantage of JAR files is that the same file works on Windows, Mac, and Linux as long as Java is installed. The disadvantage is that you have to install Java separately, and JAR programs sometimes run a bit slower because Java has to translate the code as it runs. For most everyday tasks, the difference is barely noticeable.
Frequently Asked Questions
Do I need to install Java every time I run a JAR file?
No. You install Java once on your computer, and then every JAR file you run will use that same Java installation. You only need to reinstall or update Java if you want a newer version or if Java stops working.
Can I run a JAR file on my phone or tablet?
Not directly. Phones and tablets use different operating systems (Android, iOS) that don't support Java the same way computers do. Some Java programs have been rewritten as mobile apps, but the original JAR file won't work on a phone.
What does the -jar part of the command mean?
The -jar flag tells Java that the file you're pointing to is a JAR archive and that it should look inside for the main program to run. Without it, Java won't know what to do with the file.
Is it safe to run JAR files from the internet?
JAR files can contain any code, just like .exe or .app files. Only run JAR files from sources you trust. If you read a JAR file from an unfamiliar website, scan it with antivirus software first or research the program to make sure it's legitimate.