'No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? in visual studio code

Below is the configuration in vscode. Although I have configured JDK in vscode, I am still getting the compilation error when I run maven install but maven test is working fine..

Please advise me how to resolve.

enter image description here



Solution 1:[1]

You need not configure "maven.terminal.useJavaHome", it depends on java.home, but java.home is deprecated for now.

Official docs:

If you need to compile your projects against a different JDK version, it's recommended you configure the java.configuration.runtimes property in your user settings, eg:

"java.configuration.runtimes": [
  {
    "name": "JavaSE-1.8",
    "path": "/path/to/jdk-8",
  },
  {
    "name": "JavaSE-11",
    "path": "/path/to/jdk-11",
  },
  {
    "name": "JavaSE-18",
    "path": "/path/to/jdk-18",
    "default": true
  },
]

But it will not modify the Path environment variable in the terminal, it will affect the Java extension, for example, the Run Java button.

And from the picture in your question and your comments, you need to download and install a JDK first and remember to add the bin folder of JDK to the Path environment variable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven-MSFT