OPENJDK11环境下用mvn编译未升级的JDK8项目报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin

本案参照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>

 

D:\>cd D:\004 newCoinInfo D:\004 newCoinInfo>mvn clean package [INFO] Scanning for projects... [INFO] [INFO] ------------------------< com.example:test_reg >------------------------ [INFO] Building test_reg 0.0.1-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- clean:3.2.0:clean (default-clean) @ test_reg --- [INFO] Deleting D:\004 newCoinInfo\target [INFO] [INFO] --- resources:3.2.0:resources (default-resources) @ test_reg --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] Copying 1 resource [INFO] Copying 1 resource [INFO] [INFO] --- compiler:3.10.1:compile (default-compile) @ test_reg --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 7 source files to D:\004 newCoinInfo\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.914 s [INFO] Finished at: 2023-07-19T18:31:17+08:00 [INFO] ------------------------------------------------------------------------ [WARNING] [WARNING] Plugin validation issues were detected in 2 plugin(s) [WARNING] [WARNING] * org.apache.maven.plugins:maven-resources-plugin:3.2.0 [WARNING] * org.apache.maven.plugins:maven-compiler-plugin:3.10.1 [WARNING] [WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE] [WARNING] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project test_reg: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
07-20
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值