0

There was such a problem:

Microsoft Windows [Version 10.0.22621.2134]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Oleg>echo %JAVA_HOME%
D:\Documents\java\versions\jdk20

C:\Users\Oleg>java

C:\Users\Oleg>java -version

C:\Users\Oleg>java -v

C:\Users\Oleg>

The java version is not output, although JAVA_HOME is registered and defined in PATH JAVA_HOME, PATH

Maybe someone has faced a similar problem? When deleting '\' in PATH, nothing changes

  • You can possibly start by trying `set PATH="%JAVA_HOME%\bin;%PATH%";java -version` I would get rid of that Oracle Java path – g00se Aug 21 '23 at 20:35
  • @g00se it's windows. You meant `set "PATH=%JAVA_HOME%\bin;%PATH%"` (and yes, I know that *looks* wrong). – Elliott Frisch Aug 21 '23 at 20:38
  • I'm referring to `C:\Program Files...Oracle\Java\javapath` And yes, I probably *did* mean that – g00se Aug 21 '23 at 20:42
  • thank you, everything works. I spent almost an hour on it.. – extenzzz136 Aug 21 '23 at 21:02
  • 1
    There is never a need to add things to `Path`. All you needed to do was use proper code instead of lazy and inefficient shorthand. ```"%JAVA_HOME%\bin\java.exe" -version```. Also, if you should have a need you should not just blindly prepend the variable, you should append; ```Set "Path=%Path%%JAVA_HOME%\bin;"```. Irrespective, the file has an extension, which you should **always** use. – Compo Aug 21 '23 at 21:33
  • ?? I don't know where to start... – g00se Aug 21 '23 at 21:39
  • Would you like assistance @g00se? BTW, I agree that the Oracle location could be problematic, because of its position, however, there cannot be a file with the basename `java` and any extension listed within the `PathExt` variable there, otherwise it's version would have been reported instead, _(not shown)_. – Compo Aug 21 '23 at 21:46
  • 1
    @Compo you are being inappropriately pedantic and stating an exotic approach to command line management as gospel. Separate from the merits of your approach, yelling at g00se isn't an appropriate way to interact with others, and that dictatorial tone isn't helpful. – rzwitserloot Aug 22 '23 at 01:09
  • @rzwitserloot, my comment neither yelled nor dictated, it was a response to the their questioning. If they wished some form of clarification, they should have asked instead of insinuating. My comment part agreed with them, yet showed that based upon the OP information, their suggestion was not a fix, _(despite the OP's response to it)_, and explained why. Also, they'd already been corrected by Elliott Frisch in a much less respectful way. – Compo Aug 22 '23 at 01:40
  • Please take a look on [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/a/41461002/3074564) There is explained in full details how `cmd.exe` searches for a file of which just the file name without file extension and without path is entered by a user or specified in a batch file. The environment variable `JAVA_HOME` is not evaluated by `cmd.exe` at all. There can be executed `%SystemRoot%\System32\where.exe java` to find out which file is found on using just `java` by `where.exe` and also by `cmd.exe`. – Mofi Aug 22 '23 at 06:16
  • I recommend to read the Oracle documentation page [The java Command](https://docs.oracle.com/en/java/javase/20/docs/specs/man/java.html) and [Installation of the JDK on Microsoft Windows Platforms](https://docs.oracle.com/en/java/javase/20/install/installation-jdk-microsoft-windows-platforms.html). (Shame on Oracle writing `DOS Mode` and `MS-DOS shell` because of the __Windows Command Prompt__ is __not__ a `MS-DOS shell` or a `DOS Mode`.) – Mofi Aug 22 '23 at 06:29
  • BTW in windows command line we can use the `path %JAVA_HOME%;%PATH%` without `set` and `=` – user16320675 Aug 24 '23 at 09:06

1 Answers1

0

First, try "java -version" command from the path D:\Documents\java\versions\jdk20 where you have it.

If it shows the version set the environment variable as shown below in your machine:

enter image description here

After that, try "java -version" from any location.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83