0

When trying to use java or javac in CMD, I get a

'java' is not recognised as an internal or external command, operable program or batch file

error.

The jdk bin directory is set in path:

And the JAVA-HOME is set:

echo %PATH%
...C:\Program Files\jdk-12\bin...

echo %JAVA_HOME%
C:\Program Files\Java\jdk-12

What am I missing here?

EDIT- more infomration

My PATH Config: enter image description here

And JAVA_HOME: enter image description here

dancingbush
  • 2,131
  • 5
  • 30
  • 66
  • Did you start a new CMD after setting the env variables? – lainatnavi Dec 09 '19 at 20:09
  • Can you include the _entire_ value of `%PATH%`? Maybe it's pointing to the wrong subdirectory under the JDK. `%JAVA_HOME% is not relevant here; you can ignore that. Also, this is a program-configuration question, not a programming question, so probably belongs on [Super User](https://superuser.com/) instead of Stack Overflow. – Andrew Janke Dec 09 '19 at 20:17
  • @lainatnavi yes I restarted PC and CMD, i – dancingbush Dec 09 '19 at 20:17
  • Setting the PATH variable is enough to invoke `java` and `javac` under Windows. Can you try executing `where java` from the command line? For reference, try also executing `where cmd` .. – Daniele Dec 09 '19 at 20:18
  • 1
    maybe that white space in "program files" is causing the issue? Can you move the java folder under `c:/programs/java` , edit the PATH var accordingly and retry? – Daniele Dec 09 '19 at 20:20
  • @Daniele where java INFO: Could not find files for the given pattern(s). where cmd C:\Windows\System32\cmd.exe – dancingbush Dec 09 '19 at 20:22
  • OK so the `java/bin` folder is not present in your PATH variable. Are you using `;` as delimiters between folders in PATH?. – Daniele Dec 09 '19 at 20:24
  • 2
    Just noticed the difference between what you have in the PATH and in JAVA_HOME. In PATH you are missing the \Java\ folder. Set it in the PATH like `%JAVA_HOME%\bin`. – lainatnavi Dec 09 '19 at 20:24
  • Hi All, have a look at question I have updated to demonstrate the PATH and JAVA_HOME vars – dancingbush Dec 09 '19 at 20:31
  • 1
    If this command works: `"C:\Program Files\Java\jdk-12\bin\java.exe"` append it to the system path variable. `set path=%path%;C:\Program Files\Java\jdk-12\bin`. – lainatnavi Dec 09 '19 at 20:41
  • The C:\Program Files\Java\jdk-12\bin\java.exe brought me to the executable , so I appended it to path var but am still getting same error... – dancingbush Dec 09 '19 at 20:50
  • 1
    Does the full path to the bin folder appear on the output of one of these: `reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"` or `reg query HKEY_CURRENT_USER\Environment` ? – lainatnavi Dec 09 '19 at 21:15
  • That returns JAVA_HOME REG_SZ C:\Program Files\Java\jdk-12...and the PATH returns ...;%JAVA_HOME%\bin – dancingbush Dec 09 '19 at 21:56
  • Ive just noted this only appears to be an issue if I try to run the command in an eclipse work space – dancingbush Dec 09 '19 at 22:07
  • 1
    all the variables you need to for Java: https://stackoverflow.com/questions/1672281/environment-variables-for-java-installation – sudipn Dec 10 '19 at 07:10
  • install java manually other than windows default program files directory by using https://techviewleo.com/install-java-openjdk-on-ubuntu-linux/ – HydPhani Aug 01 '22 at 20:18

1 Answers1

0

When I had set the user environment variables they did not save, simple error. Anyway anyone with similar issues this is an excellent answer: Environment variables for java installation

dancingbush
  • 2,131
  • 5
  • 30
  • 66