无法在PowerShell上识别Java [英] Java not recognized on PowerShell

查看:113
本文介绍了无法在PowerShell上识别Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 2012服务器上使用PowerShell,我从System32中删除了所有Java命令,重新安装了jdk,将JAVA_HOME和Path指向新安装.而且我仍然收到以下错误:

I'm using PowerShell on Windows 2012 server, and I deleted all the java commands from System32, reinstalled jdk, set JAVA_HOME and Path to point at the new installation. And I still get the following error:

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命令

I deleted all the java commands from System32

这就是Windows无法找到java.exe的原因.默认的JRE安装会将Java放入您的System32目录中,而CMD和Powershell通常在该目录中找到它.

This is why Windows can't find java.exe. The default JRE installation puts Java into your System32 directory, which is where CMD and Powershell usually find it.

您可以通过在管理Shell中运行以下命令为系统解决此问题.这将在Windows目录中创建java.exe的副本.(您也可以通过软链接摆脱困境)

You can fix this for your system by running the following from an admin shell. This creates a copy of java.exe in your Windows directory. (You can also probably get away with a soft link)

fsutil hardlink create (join-path $env:SystemRoot 'java.exe') (join-path $env:JAVA_HOME 'bin\java.exe')

如果您不想(或不能)修改Windows目录,则始终可以设置要在Powershell会话中使用的别名.

If you don't want to modify your Windows directory (or can't), you can always set an alias to use in your Powershell session.

Set-Alias -Name java -Value (Join-Path $env:JAVA_HOME 'bin\java.exe')

在当前会话中运行该行,并从命令行运行 java 应该可以正常工作.如果希望它在以后的所有Powershell会话中都可以使用,请将其添加到您的 $ PROFILE 中.

Run that line in your current session and running java from the command line should work correctly. Add it to your $PROFILE if you want it to work from all future Powershell sessions.

这篇关于无法在PowerShell上识别Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆