'java' is not recognized as an internal or external command, operable program or batch file in Windows 10
Asked Answered
D

1

4

I know this is a popular question on the web, but I'm getting this error even after setting JAVA_HOME env variable and adding %JAVA_HOME%\bin\ to the Path variable.

I'm trying to use PDF Presenter app which requires Java. So, I downloaded Oracle JDK (jdk-14.0.1_windows-x64_bin.exe) and installed it and then configured the above two variables.

If I enter %JAVA_HOME%\bin\java.exe --version, it works fine. But if I enter java.exe or java, I get the error in the title. How can I fix this?

Here is the output of echo %PATH%

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Git\cmd;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;%JAVA_HOME%\bin\;C:\Users\Nagabhushan\AppData\Local\Microsoft\WindowsApps;
Domineering answered 26/6, 2020 at 7:59 Comment(9)
Please share the full content of your PATH variable. Also make sure to restart your CMD after doing any changes to PATH.Iinden
have you downloaded javac properly?Cabotage
What is the output of "set path"?Easterly
@Zabuzard, here is the output of echo %PATH% -> C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Git\cmd;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;%JAVA_HOME%\bin\;C:\Users\Nagabhushan\AppData\Local\Microsoft\WindowsApps;Domineering
I've restarted cmd as wellDomineering
Try restarting your computer.Chairwoman
Restarting the computer didn't workDomineering
recheck what you have done by going through this link :- javatutorial.net/set-java-home-windows-10Sharell
I did all the work and even restarted the terminal but it was not working, the reason was that the advanced settings dialogue box was still open so changes didn't take effect, but once I pressed ok and closed the box and then restarted it, everything was working fineSharell
N
7

If you use the gui of windows for env variable don't use %JAVA_HOME% but the real path. The variable are not interpreted in the gui.

And in consequence you have %JAVA_HOME% directly in your path who will not be interpreted when you enter your command

Nomo answered 26/6, 2020 at 8:26 Comment(7)
This worked! Thanks a ton. So, I want to switch between java versions, I'll have to edit both PATH and JAVA_HOME right? Is there a way possible to avoid this?Domineering
Thier is no easy solution but a good one is jenv Who is like NVM but for javaNomo
@NagabhushanSN I find it weird this solved your problem. On my Windows 10 computer I can use %JAVA_HOME%\bin no problem (even when set in the GUI editor).Kopje
@NagabhushanSN When you set the value for JAVA_HOME did you type %JAVA_HOME% or JAVA_HOME for the variable name? You have to use the latter, then in the Path you should be able to use %JAVA_HOME%\bin.Kopje
@Iinden Ant, Maven, Gradle, IDEs... they all use this variable in some fashion. It also helps keep things more organized, in my opinion.Kopje
@Kopje I set it as JAVA_HOME only, otherwise %JAVA_HOME%\bin\java.exe --version wouldn't work right? Yes, I know it's good to reuse JAVA_HOME, but weird that it didn't work. It would be interesting to know why this problem is happening selectively.Domineering
%JAVA_HOME% just worked for me on Windows 10 using GUI: i.imgur.com/Z9EoqCg.png . Before I added the environment variable, I'd get java is not recognized as an internal or external command error when I entered java -version into the console.Deadening

© 2022 - 2024 — McMap. All rights reserved.