我的机器上安装了 Java(JRE 在 C:\Program Files\Java
下),但我无法从 Windows PowerShell 命令提示符运行任何 java 命令。
>>> java -version
java : The term 'java' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ java
+ ~~~~
+ CategoryInfo : ObjectNotFound: (java:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
但是,我注意到 Java 确实可以工作,而且我 可以 在旧的 Windows 命令提示符下运行 Java 命令。事实证明,只有 PowerShell 我无法运行这些命令。
我有 JRE 7,我在 Windows 8 上使用 Windows PowerShell。
原文由 snakile 发布,翻译遵循 CC BY-SA 4.0 许可协议
进行 2 个环境变量更改:
JAVA_HOME
变量等于:C:\Java\JDK1.7.0_25_x64
%JAVA_HOME%\bin
添加到PATH
变量的开头。然后,启动一个全新的 shell 以查看是否应用了更改。