问题描述:
使用eclipse maven install或者在项目根目录下使用./mvnw package命令打jar包,出现下面的报错No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?。
详细错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WebAPI0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ WebAPI---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ WebAPI---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 18 source files to D:\workspace\WebAPI\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: 4.404 s
[INFO] Finished at: 2022-06-30T12:08:04+08:00
[INFO] Final Memory: 21M/337M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project WebAPI: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[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
问题原因:
maven无法识别到系统环境变量里面的JAVA_HOME,或者JAVA_HOME指向目录有问题。
解决办法:
修改环境变量JAVA_HOME。JAVA_HOME 需要指向jdk1.8.0_192,我电脑上是指向C:\Program Files\Java\jdk1.8.0_192
建议同时将该路径添加系统环境变量PATH里面
如果没有生效就重启电脑。重新编译工程,再打包,问题解决了。
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.1.1:jar (default-jar) @ WebAPI---
[INFO] Building jar: D:\workspace\WebAPI\target\WebAPI.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.4.RELEASE:repackage (repackage) @ WebAPI---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ WebAPI---
[INFO] Installing D:\workspace\WebAPI\target\WebAPI.jar to D:\program\repository\com\test\WebAPI\0.0.1-SNAPSHOT\WebAPI-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\workspace\GMCWebAPI\pom.xml to D:\program\repository\com\test\WebAPI\0.0.1-SNAPSHOT\WebAPI-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.850 s
[INFO] Finished at: 2022-06-30T11:39:06+08:00
[INFO] Final Memory: 29M/334M
[INFO] ------------------------------------------------------------------------