Java Visual Studio Code 找不到 JDK8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46751168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:28:01  来源:igfitidea点击:

Visual Studio Code can't find JDK8

javavisual-studiojava-8

提问by A. Duke

I am currently trying to compile and run Java in VSC using redhat's extention and the code runner extension, though every time I try to "Run code," it tells me "Java runtime could not be located," and in the output: "'javac' is not recognized as an internal or external command, operable program or batch file." So I went into settings to tell VSC the path to my JDK. I went to "Java configuration" and inserted "java.home": C:\Program Files\Java\jre1.8.0_144 into the settings, though it gives me another error stating "Value Expected (2, 18)". This is where I'm stuck currently:

我目前正在尝试使用 redhat 的扩展和代码运行器扩展在 VSC 中编译和运行 Java,但每次我尝试“运行代码”时,它都会告诉我“无法找到 Java 运行时”,并且在输出中:“' javac' 不是内部或外部命令,也不是可运行的程序或批处理文件。” 所以我进入设置告诉 VSC 我的 JDK 的路径。我转到“Java 配置”并在设置中插入“java.home”:C:\Program Files\Java\jre1.8.0_144,尽管它给了我另一个错误,指出“Value Expected (2, 18)”。这是我目前卡住的地方:

Where I'm Stuck Currently

我目前被困在哪里

I have also tried the directory to my JDK bin with the same results. What am I doing wrong?

我还尝试将目录添加到我的 JDK bin 中,结果相同。我究竟做错了什么?

回答by Prasad madusanka

Please install Java Debugger like RedHat Extension.

请像 RedHat Extension 一样安装 Java Debugger。

These two things are compulsory to install -

这两个东西是必须安装的-

  1. Language Support for Java(TM) by Red Hat - already installed .
  2. Java Debugger for Visual Studio Code - Install this one .
  1. Red Hat 对 Java(TM) 的语言支持 - 已安装。
  2. 用于 Visual Studio 代码的 Java 调试器 - 安装这个。

Here is a shortcut -

这是一条捷径——

vscode:extension/vscjava.vscode-java-pack

vscode:extension/vscjava.vscode-java-pack

Copy and paste above line in the browser address bar and press 'Return(Enter)'. the extension will open in the VSC, Install and reload the editor.

在浏览器地址栏中复制并粘贴上面的行,然后按“回车(回车)”。扩展将在 VSC 中打开,安装并重新加载编辑器。

Go to this link

转到此链接

回答by abhay tripathi

The format of syntax is wrong. Instead of writing -

语法格式错误。而不是写 -

    "java.home": C:\Program Files\Java\jre1.8.0_144

this should be written -

这个应该写——

    "java.home": "C:/Program Files/Java/jdk1.8.0_144"

Use slash (/) instead of backslash () in file path and put quotes around it. Do recheck that jdk 8 or later is installed.

在文件路径中使用斜杠 (/) 而不是反斜杠 () 并在其周围加上引号。请重新检查是否安装了 jdk 8 或更高版本。

回答by Neon

I have faced the same problem if you are on Windows machine then open folder C:\Program Files\Java\ and look for the newest version of JDK in my case it's "jdk1.8.0_144" then enter on the right side following:

如果您在 Windows 机器上,我遇到了同样的问题,然后打开文件夹 C:\Program Files\Java\ 并在我的情况下查找最新版本的 JDK,它是“jdk1.8.0_144”,然后在右侧输入以下内容:

`{
     "java.home": "C:\Program Files\Java\jdk1.8.0_144"
 }`

If you don't have at least 1.8 then install a new one! because VS code doesn't support older versions!

如果您没有至少 1.8,请安装一个新的!因为 VS 代码不支持旧版本!

Your error says you need to put in double Slashes.

你的错误说你需要输入双斜线。

If you are on Linux then use normal slashes "/"

如果您使用的是 Linux,请使用普通斜杠“/”

Don't forget to save and restart VS code afterward to apply changes! Have a nice day

之后不要忘记保存并重新启动 VS 代码以应用更改!祝你今天过得愉快

回答by MOHAMMAD WASEEM

I fixed the issue by downloading OpenJDK from Red Hat openjdkand placing the extracted file in directory C:\ as in the image(I have renamed the file name from "java-1.8.0-openjdk-1.8.0.191-1.b12.redhat.windows.x86_64" to "java-1.8.0-openjdk-1.8.0.191" for simplicity) And change user settings in VS Code as USER SETTINGSand change workspace settings in VS Code as WORKSPACE SETTINGS

我通过从 Red Hat openjdk下载 OpenJDK并将提取的文件放在目录 C:\ 中解决了这个问题图片(我已将文件名从“java-1.8.0-openjdk-1.8.0.191-1.b12.redhat .windows.x86_64" 到 "java-1.8.0-openjdk-1.8.0.191" 为简单起见)并将 VS Code 中的用户设置用户设置更改为,并将VS Code 中的工作区设置更改为工作区设置