最近用Maven打包項目(本地jdk11)後放到服務器(jdk8)後,報【java.lang.UnsupportedClassVersionError】版本不一致錯誤。java
網上資料說是修改IntelliJ Idea的項目的源碼版本、依賴版本和JavaCompiler的編譯版本,試了事後發現沒有解決個人問題,最後經過下面的兩種解決方案解決了問題。apache
一下有兩種解決方案服務器
Java 8maven
pom.xmlui
<properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties>
Java 7插件
pom.xmlcode
<properties> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.source>1.7</maven.compiler.source> </properties>
直接選擇,配置插件xml
pom.xmlget
<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>