【问题标题】:Is it possible to select JDK 8 for Java project in Visual Studio Code?是否可以在 Visual Studio Code 中为 Java 项目选择 JDK 8?
【发布时间】:2020-12-25 11:09:50
【问题描述】:

我正在尝试使用 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


    【解决方案1】:

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

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

    【讨论】:

    • 插件说它会正确地尊重 maven 定义。文档尚未更新以反映这一点。
    【解决方案2】:

    是的,这是可能的。 您显示所有命令 (ctrl+Shift+P) 并搜索“java: configure java runtime”。 This is the screen you'll get.

    在左侧您可以看到工作区概览(确保版本 1.8 可用) 在右侧,您可以看到“Maven/Gradle Projects”点击下拉菜单,您应该可以选择jdk1.8.0。

    这应该可以解决您的问题。如果有请告诉我!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-20
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2016-05-18
    • 2021-11-11
    • 1970-01-01
    相关资源
    最近更新 更多