'jar' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# 'jar' is not recognized as an internal or external command

The error "'jar' is not recognized as an internal or external command, operable program or batch file" occurs for 3 main reasons:

  1. Not having Java Development Kit (JDK) installed on your machine.
  2. Not having the path to the directory that stores the jar.exe file in your system's PATH environment variable.
  3. Having Java Runtime Environment (JRE) installed instead of Java Development Kit (JDK).

jar is not recognized as internal or external command

Make sure you have Java Development Kit (JDK) installed and not Java Runtime Environment (JRE).

JRE contains java but doesn't contain jar and javac.

On the other hand, JDK contains java, jar and javac.

You can try to issue the where java command and look at the output to determine if you have JRE or JDK installed.

cmd
where java

where java

If you already have Java Development Kit (JDK) installed, scroll down to the "Add the path to the jar executable in your system's PATH environment variable" subheading.

To install and configure Java Development Kit (JDK) on Windows:

  1. Download the official Java Development Kit installer.

download-java-windows-installer

  1. When you start the installer, you might have to change your app recommendation settings.

change my app recommendation settings

  1. You can set the "Choose where to get apps" value to "Anywhere, but warn me before installing an app that's not from the Microsoft Store".

choose where to get apps

  1. Click on "Install anyway".

click install anyway

  1. Click on the "Next" button.

java-click-next

  1. Leave the default destination location selected and click "Next".

default java destination location

  1. Wait for the installation to complete and click on the "Close" button.

java installed successfully

  1. Restart your Command Prompt and try issuing the jar -version command.
cmd
jar --version java -jar java -version

jar get version

Likely, at this point, the jar command won't be available because the directory that contains the jar.exe file isn't automatically added to PATH.

If the error persists, you have to set the path to the jar executable in your system's PATH environment variable.

# Add the path to the jar executable in your system's PATH environment variable

To add the path to the jar executable in your system's PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "System variables" section, select the "Path" variable and click "Edit".

select path and click edit

  1. You can either click "New" and then "Browse" and navigate to the path or paste it directly.

click new browse

The path on my machine is the following:

cmd
# 👇️ this is the path on my machine (version may differ) C:\Program Files\Java\jdk-19\bin # 👇️ your path might also be similar to this C:\Program Files (x86)\Java\jdk-19\bin

path to jar exe

We are looking for the directory that contains the jar.exe file because this is the file that is run when you issue jar commands.

Notice that the path contains the jdk version, so your path will likely be different if your jdk version differs.

Note that your path should not be under a folder named jre-XYZ because Java Runtime Environment (JRE) doesn't contain the jar executable.

  1. Once you find the path to your java executable files (including jar.exe), add it and click on the "OK" button twice.

added path to jar exe

  1. Close your Command prompt application and then reopen it.
Note that you must restart your Command prompt shell for the changes to take effect.

You might also have to restart your PC, but that's not always necessary.

Open a new Command Prompt and run the jar --version command to make sure the jar executable is accessible.

cli
java -version javac -version jar --version

all java commands work

After the path to the executable (.exe) files has been added to your system's PATH environment variable, all java commands should work.

If the error persists, try restarting your PC to make sure you don't have any stale CMD, PowerShell or IDE sessions and rerun the jar --version command.

# Conclusion

To solve the error "'jar' is not recognized as an internal or external command, operable program or batch file", make sure:

  1. You have the Java Development Kit (JDK) installed on your machine.
  2. You have the path to the directory that stores the jar.exe file in your system's PATH environment variable.
  3. You don't have Java Runtime Environment (JRE) installed instead of Java Development Kit (JDK).

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.