java 命令在命令提示符中有效,但在 powershell 中无效

发布于 2025-01-10 18:56:18 字数 806 浏览 3 评论 0原文

我有以下问题。我安装了新的 OpenJDK 17:

c:\java\jdk-17.0.2

我已经为其设置了 JAVA_HOME 并在 cmd 中添加到路径:

JAVA_HOME\bin

当我输入 java -version 它可以工作。 但是当我从 VS code 或 powershell 运行它时,它显示如下:

Error: Could not open C:\java\jdk-17.0.2\lib\jvm.cfg'

有人遇到类似的问题吗?

谢谢, M.

更新#1:

这是我的环境变量设置: 环境变量

路径:

path

仍然无法正常工作: 聚苯乙烯 powershell

I have following problem. I installed new OpenJDK 17:

c:\java\jdk-17.0.2

I've set up JAVA_HOME to it and added to path:

JAVA_HOME\bin

in cmd when I type java -version it works.
But when I run it from VS code or powershell it says following:

Error: could not open C:\java\jdk-17.0.2\lib\jvm.cfg'

Has anybody faced similar issue?

Thanks,
M.

UPDATE #1:

here are my env variable settings:
env vars

path:

path

and still not working:
PS
powershell

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ双果 2025-01-17 18:56:18

您可以按照以下 5 个步骤来解决该问题:

  1. 在运行对话框中,输入 sysdm.cpl
  2. 在出现的窗口中,导航到“高级”选项卡。
  3. 单击环境变量按钮。
  4. 将 java 安装位置(bin 目录)添加到 PATH 变量中。
;%ProgramFiles%/Java/jre%version%/bin

后跟分号 ;

  1. 执行以下操作并使用新的 PowerShell 提示符再次检查

    5.1。添加一个 JAVA_HOME 变量,类似于:C:\Java\JDK-17.0.2

    5.2。将 %JAVA_HOME%\bin 添加到您的文件的开头
    路径变量。

Here are 5 steps you can follow to fix the issue:

  1. In the run dialog box, enter sysdm.cpl
  2. In the window that came up, navigate to Advanced tab.
  3. Click on the Environment Variables button.
  4. Add the location of your java installation (the bin directory) to the PATH variable.
;%ProgramFiles%/Java/jre%version%/bin

followed by a semi-colon ;

  1. Do the following and check again with a new PowerShell prompt

    5.1. Add a JAVA_HOME variable equal to something like: C:\Java\JDK-17.0.2

    5.2. Add %JAVA_HOME%\bin to the beginning of your
    PATH variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文