cmd

strange phenomenon that %JAVA_HOME% is not dir-able


I have set %JAVA_HOME% as C:\Program Files\Java\jdk-23.

When I echo %JAVA_HOME%, it will return C:\Program Files\Java\jdk-23. When I cd %JAVA_HOME%, it will take me to C:\Program Files\Java\jdk-23.

However, when I dir %JAVA_HOME%, it will complain that:

The system cannot find the path specified.

This is so strange. what's wrong?

enter image description here

Incidentally, I have set my JAVA_HOME to C:\Program Files\Java\jdk-23, but where java returns C:\Program Files\Common Files\Oracle\Java\javapath\java.exe. Does it matter?


Solution

  • The issue is that the %JAVA_HOME% path contains spaces, which are delimiters, so it won't find the correct file The solution is to change your command to:

    dir "%JAVA_HOME%"
    

    cdworks because, as per the documentation,

    Spaces aren't treated as delimiters, so can contain spaces without enclosing quotation marks. For example: cd username\programs\start menu