首页 > 解决方案 > 是否可以在 Visual Studio Code 中为 Java 项目选择 JDK 8?

问题描述

我正在尝试使用 Visual Studio Code 编译和运行基于 maven 的 Java 项目。

VSCODE 本身需要 JDK 11。我安装了 JDK 11 并将其添加为 VSCODE“Java:配置 Java 运行时”部分中的 java.home。

然而,该项目需要 Java 8。我有 JAVA_HOME 指向的 JDK 8,并且 pom.xml 指定

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

但是,当我编译并尝试在 VSCODE 中运行项目时,我会收到消息

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.

即使 VSCODE 知道 JDK 8 是可访问的:

在此处输入图像描述

如何指示 VSCODE 使用 JDK 8(而不是 JDK 11)作为项目的运行时?

标签: visual-studio-code

解决方案


是的,虽然 VSCode 支持 Java 1.5 及更高版本的项目,但它是可能的。您需要专注于运行时配置。检查下面的链接。 Java 运行时 VSCode

同时,我强烈建议您使用其他 IDE,如 eclipse 或 Intellij 来进行 Java 项目的正确调试、透视、maven、gradle、库支持等


推荐阅读