无法在PowerShell上识别Java
我在Windows
2012服务器上使用PowerShell,我从System32删除了所有Java命令,重新安装了jdk,将JAVA_HOME和Path设置为指向新安装。而且我仍然收到以下错误:
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
回答:
我从System32删除了所有Java命令
这就是Windows无法找到java.exe的原因。默认的JRE安装将Java放入System32目录,而CMD和Powershell通常在该目录中找到Java。
您可以通过从管理shell运行以下命令来为您的系统解决此问题。这将在Windows目录中创建java.exe的副本。(您也可以通过软链接摆脱困境)
fsutil hardlink create (join-path $env:SystemRoot 'java.exe') (join-path $env:JAVA_HOME 'bin\java.exe')
如果您不想(或不能)修改Windows目录,则始终可以设置一个别名在Powershell会话中使用。
Set-Alias -Name java -Value (Join-Path $env:JAVA_HOME 'bin\java.exe')
在当前会话中运行该行,并且java
从命令行运行应该可以正常工作。$PROFILE
如果您希望它在以后的所有Powershell会话中都能使用,请将其添加到您的文件中。
以上是 无法在PowerShell上识别Java 的全部内容, 来源链接: utcz.com/qa/419855.html