无法从Windows PowerShell命令提示符运行Java [英] Cannot run Java from the Windows PowerShell command prompt

查看:790
本文介绍了无法从Windows PowerShell命令提示符运行Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器上安装了Java(JRE在 C:\Program Files \ Java 下),但我无法从Windows运行任何java命令PowerShell命令提示符。

I have Java installed on my machine (the JRE is under C:\Program Files\Java) but I can't run any java command from the Windows PowerShell command prompt.

>>> 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,我无法运行这些命令。

However, I have noticed that Java does work and that I can run Java commands on the old Windows command prompt. Turns out it's only PowerShell where I can't run those commands.

我有JRE 7,我在Windows 8上使用Windows PowerShell。

I have JRE 7 and I'm using Windows PowerShell on Windows 8.

推荐答案




  • 在运行对话框中,输入 sysdm.cpl

  • 在出现的窗口,导航到高级选项卡。单击 Environment Variables 按钮。

  • 将java安装的位置(bin目录)添加到 PATH 变量。

    • In the run dialog box, enter sysdm.cpl
    • In the window that came up, navigate to Advanced tab. Click on the Environment Variables button.
    • Add the location of your java installation (the bin directory) to the PATH variable.

      ;%ProgramFiles%/Java/jre%version%/bin
      

      后跟;

      注意:

      %version% means the java version.
      

      这篇关于无法从Windows PowerShell命令提示符运行Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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