You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode中“Configure Java Runtime”无法修改Java版本求助

解决VSCode中Java Web项目Java版本无法保存的问题

手动修改项目核心配置文件

  • 找到项目根目录下的.settings/org.eclipse.jdt.core.prefs文件,打开后修改以下两行内容:
    org.eclipse.jdt.core.compiler.source=1.8
    org.eclipse.jdt.core.compiler.target=1.8
    
    保存文件后重启VSCode,版本设置即可生效。

Maven项目直接修改pom.xml

如果你的项目用Maven管理,直接在pom.xml中添加或更新配置:

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

<!-- 可选:指定编译器插件版本确保兼容性 -->
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

保存pom.xml后,Maven会自动同步配置,Java版本会切换到1.8。

配置VSCode项目级运行时设置

打开项目的.vscode/settings.json(没有的话直接新建这个文件),添加Java8的运行时配置:

{
    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "你的Java8安装路径",
            "default": true
        }
    ]
}

把你的Java8安装路径替换成实际路径(比如Windows下的C:\Program Files\Java\jdk1.8.0_381,Mac下的/Library/Java/JavaVirtualMachines/jdk1.8.0_381.jdk/Contents/Home),保存后重启VSCode即可。

确认Java8运行时已被VSCode识别

打开VSCode命令面板(Ctrl+Shift+P),输入Java: Configure Java Runtime,在「Installed Runtimes」列表里确认Java8已被正确识别。如果没显示,点击「Add」按钮手动添加Java8的安装路径,并设置为默认运行时。

内容的提问来源于stack exchange,提问作者Oliver Steiner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 02:05:25