setting environmental variable in windows using cm

2020-03-26 13:52发布

问题:

To start the my project in windows i have to set the java environmental variable in cmd using below command

set JAVA_HOME = D:\Java\jdk1.7.0

but it didn't set the environment variable, i don't know what the issue.After pending couple hours i find the reason that is due to white space on both side of = symbol.Because of this environmental variable not getting set and i changed by command to

set JAVA_HOME=D:\Java\jdk1.7.0

after that it is working fine.

My question is why this both command are not equal?

回答1:

The set command is aware of spaces. When you issue the command

set JAVA_HOME = D:\Java\jdk1.7.0

you actually set the variable JAVA_HOME␣ to value ␣D:\Java\jdk1.7.0. Note the spaces: !

You can check it using the following way:

> echo [%JAVA_HOME%]
[%JAVA_HOME%]
> echo [%JAVA_HOME %]
[ D:\Java\jdk1.7.0]

The brackets are included in order to highlight spaces, they are not important by themselves.



标签: windows cmd