Java在cmd中运行,但不在PowerShell中运行 [英] Java runs in cmd, but not from the PowerShell

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

问题描述

我刚刚将java文件夹添加到我的环境变量中。当我尝试从Windows命令行(cmd)执行 javac HelloWorld.java java HelloWorld 时,它正常执行。但是,如果我打开Windows Powershell并执行相同操作,它会说:

I just added the java folder to my Environment Variables. When I try to execute, for example, javac HelloWorld.java and java HelloWorld from the Windows command line (cmd), it executes normally. But if I open Windows Powershell and do the same, it says:

javac : The term 'javac' is not recognized as the name of a cmdlet, function, script file, or operable program. Check t
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ javac HelloWorld.java
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (javac:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

另外,如果我在cmd中编译HelloWorld.java,则可以从Powershell运行 java HelloWorld

Also, if I compile HelloWorld.java in cmd, it is possible to run java HelloWorld from the Powershell.

如何从Powershell执行javac?

How can I execute javac from the Powershell?

推荐答案

验证你从powershell中的$ env:path获得了什么。同样来自cmd echo%path%
如果在powershell路径中不包含javapath,请确保正确添加。

Verify what you got from $env:path in powershell. Also from cmd echo %path% If javapath is not contain in powershell path, make sure you add properly.

这篇关于Java在cmd中运行,但不在PowerShell中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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