是否可以在 Visual Studio Code 中为 Java 项目选择 JDK 8? [英] Is it possible to select JDK 8 for Java project in Visual Studio Code?

查看:41
本文介绍了是否可以在 Visual Studio Code 中为 Java 项目选择 JDK 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

但是该项目需要 Java 8.我有JAVA_HOME指向的JDK 8,pom.xml指定

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>

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

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.

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

Even though VSCODE knows JDK 8 is reachable:

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

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

推荐答案

是的,虽然 VSCode 支持 Java 1.5 及更高版本的项目.您需要关注运行时配置.检查下面的链接.Java 运行时 VSCode

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

同时,我强烈建议您使用其他 IDE,例如 Eclipse 或 Intellij 用于 Java 项目,以进行适当的调试、透视、maven、gradle、库支持等

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

这篇关于是否可以在 Visual Studio Code 中为 Java 项目选择 JDK 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆