sergey_o
sergey_o

Reputation: 309

Is it possible to select JDK 8 for Java project in Visual Studio Code?

I am trying to use Visual Studio Code to compile and run a maven-based Java project.

VSCODE requires for itself JDK 11. I installed JDK 11 and added it as java.home in VSCODE "Java: Configure Java Runtime" section.

The project however requires Java 8. I have JDK 8 pointed by JAVA_HOME, and pom.xml specifies

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

However when I compile and try to run the project in VSCODE, I get messages

Build path specifies execution environment JavaSE-1.8. There are no JREs installed in the workspace that are strictly compatible with this environment. 

The compiler compliance specified is 1.8 but a JRE 11 is used.

Even though VSCODE knows JDK 8 is reachable:

enter image description here

How do I instruct VSCODE to use JDK 8 (rather than JDK 11) as runtime for the project?

Upvotes: 6

Views: 16603

Answers (2)

Yes it is possible as VSCode support projects from Java 1.5 and above although. You need to focus on the runtime configuration. Check the link below. Java Runtime VSCode

Meanwhile, I will strongly recommend you use other IDEs like eclipse or Intellij for Java projects for proper debugging, perspectives, maven, gradle, library support, etc

Upvotes: 1

Wovi10
Wovi10

Reputation: 23

Yes this is possible. You show all commands (ctrl+Shift+P) and search for "java: configure java runtime". This is the screen you'll get.

On the left side you can see workspace overview (make sure version 1.8 is available) On the right side, you can see "Maven/Gradle Projects" click on the drop down menu and you should be able to select the jdk1.8.0.

This should solve your problem. Please let me know if it did!

Upvotes: 0

Related Questions