最近用Maven打包项目(本地jdk11)后放到服务器(jdk8)后,报【java.lang.UnsupportedClassVersionError】版本不一致错误。

网上资料说是修改IntelliJ Idea的项目的源码版本、依赖版本和JavaCompiler的编译版本,试了过后发现没有解决我的问题,最后通过下面的两种解决方案解决了问题。

一下有两种解决方案

1. Maven Properties

Java 8

pom.xml

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

Java 7

pom.xml

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

2. Compiler Plugin

直接选择,配置插件

pom.xml

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
05-07 15:17
查看更多