我的机器上安装了 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。
最佳答案
修改两个环境变量:
- 添加一个
JAVA_HOME
变量等于:C:\Java\JDK1.7.0_25_x64
- 将
%JAVA_HOME%\bin
添加到PATH
变量的开头。
然后,启动一个全新的 shell 以查看是否应用了更改。
关于powershell - 无法从 Windows PowerShell 命令提示符运行 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16811332/