本案参照URI:https://blog.csdn.net/qq_38872310/article/details/79915069
本处可以肯定是jre版本不对称的问题,如果JDK8项目需要升级,可以通过调节eclipse或者ideaij里面的jdk版本,尝试解决。
但是如果项目未进行升级,仍旧用JDK8,只是mvn打包时需要到linux服务器上进行打包,但是linux服务器上的JDK却先
一步由JDK8升级到了OPENJDK11。因此就会存在mvn编译时编译不通过问题。
以下是具体解决办法。
一、在项目的pom.xml中添加如下代码(注意位置)
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf8</encoding>
<skip>true</skip>
<executable>${JAVA8_HOME}/bin/javac</executable> // 个人认为此处指定了mvn进行编译时所运行的JAVA坏境(本案指定了maven设置文件setting.xml内配置的JDK8的路径)
<compilerArgs>
<arg>-verbose</arg>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation</arg>
<arg>-bootclasspath</arg>
<arg>${JAVA8_HOME}/jre/lib/rt.jar:${JAVA8_HOME}/jre/lib/jce.jar</arg> // 如果项目中引用了JDK8下面的JAR包,也需要指定路径
<arg>-extdirs</arg>
<arg>src/main/webapp/WEB-INF/lib</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
二、在maven的插件里,修改setting.xml里的配置
<profiles> // 本案此处添加了2个JDK路径的指向,可根据需要进行选择性添加
<profile>
<id>custom1-compiler</id>
<properties> <JAVA8_HOME>D:\Java\jdk1.8.0_161</JAVA8_HOME> </properties> // JDK8路径
</profile>
<profile>
<id>custom-compiler</id>
<properties> <JAVA_HOME>D:\Java\openjdk-11.0.2</JAVA_HOME> </properties> // openjdk-11路径
</profile>
</profiles>
<activeProfiles>
<activeProfile>custom1-compiler</activeProfile>//激活上面的配置 和上面的ID对应,就是激活对应的配置
<activeProfile>custom-compiler</activeProfile>//激活上面的配置 和上面的ID对应,就是激活对应的配置
</activeProfiles>