Java 在 cmd 中运行,但不能在 PowerShell 中运行

2023-12-20

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

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,则可以运行java HelloWorld来自 Powershell。

如何从 Powershell 执行 javac?


验证您从 powershell 中的 $env:path 获得的内容。也来自 cmd echo %path% 如果 powershell 路径中不包含 javapath,请确保正确添加。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java 在 cmd 中运行,但不能在 PowerShell 中运行 的相关文章

随机推荐