All company projects I work for use Java 8. However I want to try working with VSCode for Java. The problem is that it asks me for Java 11 to make the Java extension work (plus I want to start doing personal projects with java 11).
Right now in the path (windows environment), I have java 8. If I put java 11 in the path, although it is supposed to be backward compatible, they have deprecated and removed many things so colleagues have told me that it will give many problems.
How can I work with java 8, java 11, and VSCode? What is the configuration that I must have in the path (Windows environment) and how can I configure VSCode so that each project works with its own SDK? I have looked at the documentation for VSCode, but I don't understand it very well.
One thing is your installed jdk, you can have many jdk installed 8,11,16... but it's suggested have jdk11+ installed for working well on vscode.
Except your installed jdk versions, each java project can have your own version java setted ( in pom.xml, in build.grable... )
After installed JDK11+ you can open your java project ( even on java8 version ) and choose both:
It's possible use jdk11 and working in project with Java 8
don't forget to install Extension Pack for Java ( vscjava.vscode-java-pack ) on vscode
press CTRL + SHIFT + P and search for 'configure java runtime'
you will got 3 tabs to set:
Clean your workspace after change settings
press CTRL + SHIFT + P and search for 'Clean java Language'. Vscode will be reseted and refreshed
The JRE for running the VSCode Java Extension is included in the Red Hat Java Extension, so there is no need to configure java.jdt.ls.home or the deprecated java.home. Install the JDK versions you want to use in your project and specify the version in the files below.
settings.json ≫ java.configuration.runtimes ≫ "default": truesettings.json ≫ java.import.gradle.java.homebuild.gradle ≫ java ≫ sourceCompatibilitysettings.json ≫ maven.terminal.customEnv ≫ "JAVA_HOME"pom.xml ≫ properties ≫ maven.compiler.source (or java.version for Spring Boot)(*1) Tools Java Home: The settings.json can be configured by workspace (project).
(*2) The java.configuration.runtimes that best matches this version will be used.
The settings.json can also be automatically configured with Java Extension Pack Auto Config.
// Project Runtimes (multiple versions)
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "C:\\Program Files\\java\\jdk1.8.x"
},
{
"name": "JavaSE-17",
"path": "C:\\Program Files\\java\\jdk-17.0.x"
},
{
"name": "JavaSE-21",
"path": "C:\\Program Files\\java\\jdk-21.0.x",
"default": true // Runtime to use for No build tools projects
}
],
// Gradle Daemon Java Runtime
"java.import.gradle.java.home": "C:\\Program Files\\java\\jdk-21.0.x",
// Maven Environment Variables (for GUI context menu)
"maven.terminal.customEnv": [
{
"environmentVariable": "JAVA_HOME",
"value": "C:\\Program Files\\java\\jdk-21.0.x"
}
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With