MacOS 14.0下IntelliJ IDEA中JDK8应用无法用指定JDK运行的问题
解决SpringBoot应用在IntelliJ IDEA中错误使用JDK17而非JDK1.8的问题
针对Mac 14.0环境下,IDEA 2023.3中JDK1.8的SpringBoot项目误跑在JDK17上的问题,按以下步骤排查修复:
检查运行/调试配置
打开右上角运行配置下拉框 → 选择Edit Configurations...,找到你的SpringBoot应用配置:- 切换到
JRE标签页,确认选择的是JDK 1.8,而非Default或JDK17。若选了Default,需先修改全局默认JDK。
- 切换到
确认项目与模块SDK配置
打开File → Project Structure(快捷键⌘+;):- 在
Project Settings → Project中,设置Project SDK为JDK1.8,Project language level选择8 - Lambdas, type annotations etc. - 切换到
Modules,检查所有模块的SDK和Language level均为JDK1.8标准。
- 在
强制Maven使用JDK1.8编译
在项目pom.xml中添加maven-compiler-plugin配置,明确指定JDK版本:<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> <release>8</release> </configuration> </plugin> </plugins> </build>若项目继承了Spring Boot parent,可省略插件版本,但需保留source/target/release配置。
重置IDEA缓存
打开File → Invalidate Caches...,选择Invalidate and Restart,重启后重新加载项目,清除可能的配置缓存。修正IDEA全局Maven Runner配置
打开File → Settings(快捷键⌘+,)→Build, Execution, Deployment → Build Tools → Maven → Runner:- 将
JRE设置为JDK1.8,或勾选Use project SDK - 同时进入
Build, Execution, Deployment → Compiler → Java Compiler,确认Project bytecode version及所有模块的bytecode版本均为1.8。
- 将
手动指定IDEA中的JDK路径
由于Mac的/usr/libexec/java_home指向JDK17,可直接在IDEA中添加JDK1.8的具体路径:- 在
Project Structure → SDKs中,点击+选择JDK,找到JDK1.8的安装目录(如/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home),添加后设为项目默认SDK。
- 在
内容的提问来源于stack exchange,提问作者Rollsbean
相关产品推荐
相关产品推荐

