简体   繁体   English

Visual Studio Code 找不到 JDK8

[英]Visual Studio Code can't find JDK8

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."我目前正在尝试使用 redhat 的扩展和代码运行器扩展在 VSC 中编译和运行 Java,尽管每次我尝试“运行代码”时,它都会告诉我“找不到 Java 运行时”,并且在输出中:“” javac' 不是内部或外部命令、可运行程序或批处理文件。” So I went into settings to tell VSC the path to my JDK.所以我进入设置告诉 VSC 我的 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)".我转到“Java 配置”并在设置中插入“java.home”:C:\Program Files\Java\jre1.8.0_144,尽管它给了我另一个错误,指出“预期值 (2, 18)”。 This is where I'm stuck currently:这是我目前陷入困境的地方:

我目前卡在哪里

I have also tried the directory to my JDK bin with the same results.我还尝试了我的 JDK bin 的目录,结果相同。 What am I doing wrong?我究竟做错了什么?

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或更高版本。

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! 如果你没有至少1.8,那么安装一个新的! because VS code doesn't support older versions! 因为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! 不要忘记以后保存并重新启动VS代码以应用更改! Have a nice day 祝你今天愉快

I fixed the issue by downloading OpenJDK from Red Hat openjdk and placing the extracted file in directory C:\\ as in the 我通过从Red Hat openjdk下载OpenJDK并将解压缩的文件放在目录C:\\中解决了这个问题。 图片 (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 (为简单起见,我将文件名从“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中的用户设置为 用户设置 and change workspace settings in VS Code as 并将VS Code中的工作区设置更改为 工作空间设置

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 . Red Hat的Java(TM)语言支持 - 已经安装。
  2. Java Debugger for Visual Studio Code - Install this one . Visual Studio代码的Java调试器 - 安装此调试器。

Here is a shortcut - 这是一个捷径 -

vscode:extension/vscjava.vscode-java-pack vscode:扩展/ vscjava.vscode的Java包

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 转到此链接

For everyone who ended here with an jdk installed through asdf:对于通过 asdf 安装了 jdk 到这里结束的每个人:

It turned out I did not update my JAVA_HOME env variable properly.结果我没有正确更新我的JAVA_HOME变量。

Setting it like documented here solved the problem for me: https://github.com/halcyon/asdf-java#java_home像这里记录的那样设置它为我解决了这个问题: https : //github.com/halcyon/asdf-java#java_home

I had the same problem today, after a few hours trying to find why it stoped working, came to my solution.我今天遇到了同样的问题,经过几个小时试图找出它停止工作的原因后,我找到了解决方案。 Java updated and there was an empty older vesion folder left in the c:\program files\java, just deleted and everything is working again. Java 更新了,在 c:\program files\java 中留下了一个空的旧版本文件夹,刚刚删除,一切都恢复正常了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM