简体   繁体   中英

Java on VSCode Extension Pack for Java can't detect jdk

I am trying to run java on vscode however the 'Extension Pack for Java' keeps asking me to redownload the jdk. I am able to run java on intellij and have been using that but since I use vscode for everything else I would like to get it to work on my main editor.

Here are the settings related to java

 "java.help.firstView": "gettingStarted", "java.home":"/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java", "java.jdt.ls.java.home": "/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java", "java.configuration.runtimes": [ { "name": "JavaSE-17", "path": "/Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home/bin/java", }, { "name": "JavaSE-17", "path": "/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/bin/java", }, { "name": "JavaSE-17", "path": "/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java", "default": true }, ],

enter image description here

Error The java.home variable defined in Visual Studio Code settings points to a missing or inaccessible folder (/Library/Java/JavaVirtualMachines/adoptopenjdk-17.jdk/Contents/Home)

any ideas?

All other languages I use work fine, it just seems to be java.

Assume you are using the latest Java extensions, here are some suggestions:

  1. java.home has been deprecated, please don't use it and use java.jdt.ls.java.home instead
  2. The latest Java extension already embeds a jre 17, you can find it in $home/.vscode/extensions/redhat.java-1.x.0/jre . Ideally there is no need to specify java.jdt.ls.java.home , unless your platform is not covered.
  3. If your platform is not covered, then you need to manually set java.jdt.ls.java.home , which should point to the home path of your JDK installation. So please update it to /Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home .
  4. java.configuration.runtimes is used to map different JDK versions to their installation path. Please make sure each version only appear once in this setting.

JVM cant be found if it is installed in a directory owned by root (like /usr/lib/jvm), install the VM in a directory in your own home folder, that worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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