Reputation: 667
I was making a java program in VSCode and I noticed that suggestion, error reporting and autocomplete features are not working. A notification showing below error popped up:
Sorry, something went wrong activating IntelliCode support for Java. Please check the "Language
Support for Java" and "VS IntelliCode" output windows for details.
I tried finding the error in settings but couldn't find any. Also I tried first uninstalling and then reinstalling the above mentioned extension, but it didn't help.
Any help much appreciated!!
Upvotes: 18
Views: 48004
Reputation: 1275
The Language Support for Java extension now contained a Java runtime by itself, which is used to launch the extension. That means in most cases, you don't need to specify java.home
and jdt.ls.java.home
.
All you need to do is use the setting java.configuration.runtimes
to specify all the JDKs you have installed on your machine. Then the extension will pick the most suitable JDK according to your project's configuration.
There are two kinds of JDKs that VS Code Java will use.
I guess your problem is caused by that the Language Server cannot find a valid JDK to launch itself. (See the next paragraph about how to fix it)
The first kind is the JDK that is used to launch the Java Language Server, which requires JDK 11 or higher. And the setting java.home
is used to specify which JDK is used to launch the Language Server. Make sure you set this setting and the Java version is >= 11.
The second kind is the JDKs that is used to build/launch your project. That's controlled by the setting java.configuration.runtimes
, which is also mentioned by @Jayan Praveen's answer.
Upvotes: 8
Reputation: 522
To fix this:
- Open VScode and go to Preferences -> Settings
- Search java.configuration.runtimes
- Select Edit in settings.json and paste the follwing:
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "/path/to/jdk-8",
},
{
"name": "JavaSE-11",
"path": "/path/to/jdk-11",
"default": true
},
{
"name": "JavaSE-14",
"path": "/path/to/jdk-14",
},
]
- Specify the path of the JDK which you would like to use in "path:"
usually the path of JDK for macOS is
/Library/Java/JavaVirtualMachines/
- Set "default": true for that JDK
Suppose if you would like to use JDK 11, set "default": true in that code block.
Check for additional information here.
Upvotes: 22