Maven版本不一致的时候,使用指定版本进行编译


最近用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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM