用IDEA创建一个Spring Boot 项目时,在maven面板中执行package命令时报错,输出Unsupported major.minor version 52.0的错误

问题描述

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/yf/springboot/Application : Unsupported major.minor version 52.0

IDEA的环境

IDEA的环境是:

  1. JRE采用了jdk1.7版本   
  2. pom.xml文件中spring-boot-starter-parent的version配置的是2.x

如何处理

由此推断是由于1.8版本的jdk与springboot 2.x版本的匹配问题导致。 通过修改IDEA的配置,修改路径入下:

//mac os
Preferences -> Build,Execution,Deployment -> Build Tools -> Maven -> Runner

修改IDEA的JRE版本为 1.8 后解决

/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/xxx/workspace/javaprojects/spring-boot-demo-1 "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-Dmaven.ext.class.path=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven-event-listener.jar" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=64844:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds.license:/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.6.0.jar" org.codehaus.classworlds.Launcher -Didea.version=2020.2 package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] spring-boot-demo-1                                                 [pom]
[INFO] m1                                                                 [jar]
[INFO] 
[INFO] -------------------< com.bugtags:spring-boot-demo-1 >-------------------
[INFO] Building spring-boot-demo-1 1.0-SNAPSHOT                           [1/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] ---------------------------< com.bugtags:m1 >---------------------------
[INFO] Building m1 1.0-SNAPSHOT                                           [2/2]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ m1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ m1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/xxx/workspace/javaprojects/spring-boot-demo-1/m1/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ m1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/xxx/workspace/javaprojects/spring-boot-demo-1/m1/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ m1 ---
[INFO] Changes detected - recompiling the module!
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ m1 ---
[INFO] 
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ m1 ---
[INFO] Building jar: /Users/xxx/workspace/javaprojects/spring-boot-demo-1/m1/target/m1-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.13.RELEASE:repackage (repackage) @ m1 ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for spring-boot-demo-1 1.0-SNAPSHOT:
[INFO] 
[INFO] spring-boot-demo-1 ................................. SUCCESS [  0.002 s]
[INFO] m1 ................................................. SUCCESS [  2.427 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.730 s
[INFO] Finished at: 2020-11-20T12:36:04+08:00
[INFO] ------------------------------------------------------------------------