25

I'm getting the following error when I try to run the 'jar' command in the command line on windows : 'jar' is not recognized as an internal or external command

The general solution seems to be that I need to add the jdk bin folder to the PATH in environment variables. I have already done this, I added the following to the path variable : ...; C:\Program Files\Java\jdk1.8.0_40\bin\;

Though I'm not sure if having the jdk reside in 'program files' instead of 'program files x86' affects this. I'm on 64 bit windows with 64 bit java. Thanks

Coder Lam
  • 395
  • 1
  • 3
  • 13

4 Answers4

22

The path should only contain directories where the OS will look for executables. Strip the trailing "\jar.exe" to set your path as:

(old path variables here);C:\Program Files (x86)\Java\jdk1.7\bin

Thanks To : @stevevls

Joseph Mekwan
  • 1,082
  • 1
  • 15
  • 28
9

Try using this command:

java -version

If it doesn't work that means you failed to properly add path to jdk. If it does work, try using:

java -jar
3

The jar command in command line is used in order to create a JAR file. For example:

 jar cf jar-file input-file(s)

See more at: Oracle docs

If you want to run the existed JAR file you should use the java -jar command mentioned by @Aleksandr.

But in your case it looks like you don't have an access to the added directory in your path with JKD binaries so at the beginning try to execute mentioned java --version to check whether you have java in you classpath at all.

Please remember that on Windows you have to restart the console when you change the windows default path. You do not see the changes on the current console.

The x64 version of Java is installed on Program Files. The x86 version is installed on Program Files x86 by default.

Przemek Nowak
  • 7,173
  • 3
  • 53
  • 57
  • I can run java -version and java -jar. Can you clarify how simply running 'jar...' vs 'java -jar...' differ ( and what causes one to fail when the other doesn't?). Is it an issue with the classpath? Thanks – Coder Lam Mar 21 '15 at 18:27
  • The "java -jar" command is used to run JAR-Packaged software. The JAR file needs to contain the Main class. See more at http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file. The "jar" command is used to package the software to JAR file. See more at http://stackoverflow.com/questions/4597866/java-creating-jar-file – Przemek Nowak Mar 21 '15 at 20:11
2

Five steps to solve this problem:

  1. check whether in your bin folder jar.exe is availbale or not
  2. check for your environmental setting
  3. download jar file from here http://originaldll.com/file/jar.exe/29248.html and keep in bin folder
  4. now check for jar it will 100% work
  5. keep any jar in your desktop and go to desktop path on cmd prompt and run the command jar xf filename.jar

Now see if it is working

MWiesner
  • 8,868
  • 11
  • 36
  • 70