JAR files, also called Java Archives files, are archives of Java class files. In a nutshell, JAR files are groups of files that can contain images, audio, visuals, etc., and can run as a single executable program when paired with the Java Runtime Environment.
They are predominantly used by Java developers for coding and programming. However, jar files refusing to open is one of the many issues that can happen while using them.
Why Does My JAR File Not Open?
Here are the possible causes for your jar file refusing to open.
- JAR file set to open with other applications.
- Java Runtime Environment having issues.
- Incompatible JRE or JDK version
- Incorrect Filename Extension
How to Fix JAR File Not Opening?
There are several methods you can use to fix JAR files not opening. However, before you begin, ensure the JAR file has the correct filename extension. To do so, go to the View tab and enable File name extensions. Make sure the JAR file has .jar
at the end.
Make your way down the list of fixes to see which one works for you.
Set JRE as Default for JAR files
For the JAR files to be opened as a standalone program, you need to have the JAVA Runtime Environment. However, if the JRE is not set as the default application for opening jar files, your computer tries using different applications to open the file and fails to do so.
So, you should set the JRE as the default application for opening JAR files.
- Click on the specific Jar file you want to open and right-click it.
- Select Open with and Choose another app.
- Check mark Always use this app to open .jar files option.
- Click on More apps and Look for another app on this pc.
- Navigate to C:\Program Files\Java\jre\bin. (This is the default installation path of Java. If you have installed it in another folder, go there instead. The JRE folder may also differ depending on your JRE version.)
- Select javaw.exe and hit Open.
You can also enter assoc .jar=jarfile
and ftype jarfile="C:\(path to your javaw.exe)" -jar "%1" %*
command in an Elevated Command Prompt to set JRE as the default application.
For Example:ftype jarfile="C:\Program Files\Java\jre1.8.0_341\bin\javaw.exe”
However, you need to make sure of the following things.
- Enter the commands in the same order.
- Ensure to input the directory path to your JRE in the second command.
- Make sure the path is set to your JRE instead of JDK.
Use Command Prompt
You can also easily open jar files using command lines in the Command Prompt.
Here’s how you can do it:
- Launch Run Utility using Windows key + R key.
- Enter
cmd
to open Command Prompt. - In Command Prompt, type
cd
and enter the directory to your.jar
file. (If the.jar
file is on another drive, you need to change the selected drive by entering the driver letter.) - If you don’t know how to enter the folder directory in Command Prompt, you can simply drag and drop the folder from File Explorer to Command Prompt.
- Enter the
Java -jar <Your Jar filename.jar>
command.
If your jar file is non-executable, the above method won’t work on opening it. You would need to use a different command.
- In Command Prompt, enter the command
java -cp app.jar com.<package name>.<class name>
- If you were not the one to create the jar file and therefore do not know the package name and class name, you can look it up on the downloaded website.
Setup a BAT File
Another method you can use to open .jar
files is by creating a .bat
file scripted to open a particular file. This method skips the normal method of opening the .jar
file and helps resolves issues like this.
Follow the steps below:
- Right-click on the empty area in the folder where your jar file is located and choose New.
- Select Text Document and open the document as is.
- Type in
Java -jar <Your Jar filename.jar>
- Go to File > Save as.
- Make sure the Save as type option is selected as All files.
- Name the text document anything you want, but include a
.bat
extension at the end. - Click Save.
- Open the
.bat
file.
For non-executable .jar
files, you can use the same command as above to create a .bat
file that opens it.
Use Compatible Java Version
If you have multiple Java versions and are trying to open a jar file made in a different version of Java from the one you are using to open it, the jar file may not open. While Java is supposed to be backward compatible, you may still face this issue sometimes.
To solve this, you must define a compatible version with which the jar file should open.
Here’s how you can do it:
- Right-click your jar file and tap on Create shortcut.
- Right-click the shortcut and select Properties.
- Next to target, enter the following:
“C:\(path to your compatible jdk or jre version)” -jar “C:\(path to your jarfile.jar)”
For e.g."C:\Program Files\Java\jre1.8.0_341\bin\javaw.exe" -jar "C:\Users\Username\Downloads\myjarfile.jar"
- Click Apply and OK.
- Open the shortcut.
You can also use this method in the Command prompt or create a bat file to open jar files.
Reinstall JAVA Runtime Environment
The jar files can not start as a standalone program without JRE, so JRE must be working properly to open jar files.
If there are any errors in JAVA Runtime Environment, you can reinstall a clean new copy to nullify any issues plaguing it.
Follow the steps below to reinstall it:
- Access Settings from the Start menu.
- Navigate to Apps > Apps & features.
- Locate Java and click on options button on the left.
- Select Uninstall and confirm Uninstall.
- Download the latest Java build from its official website.
- Run the setup file to install Java.
Run Jarfix
Jarfix is a legit software that many Java developers use to troubleshoot issues with jar files. So, you can run Jarfix to fix issues with your jar files, including issues like jar files refusing to open.
It is a lightweight program and doesn’t use many system resources. However, be sure to download this program from a trusted website.