概述:
一般是jre版本不对称的问题,可以通过调节eclipse面的jdk版本,尝试解决。
出现过程:
用eclipse的maven插件编译时
提示
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.demo.dubbo:dubbo-api >----------------------
[INFO] Building dubbo-api 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dubbo-api ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dubbo-api ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\zlq\zoom_eclipse\li\dubbo-api\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: 2.141 s
[INFO] Finished at: 2019-04-11T09:52:35+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project dubbo-api: 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
分析:
对这个问题其实报错中已经说的很清楚了,看第一条最后的 Perhaps you are running on a JRE rather than a JDK?
就是说你可能编译在一个JRE而不是JDK上,maven 编译是要JDK的,可能你的编译器配置了一个jre路径。
解决:
在eclipse中,选择window→preference→java→Installed JREs 点add添加你的jdk路径,选jdk而不是jre,之前的报错原因就出在这里。
然后右键你的maven工程,在maven中点击update project
最后 maven clean,maven install
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.demo.dubbo:dubbo-api >----------------------
[INFO] Building dubbo-api 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dubbo-api ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dubbo-api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dubbo-api ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\zlq\zoom_eclipse\li\dubbo-api\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ dubbo-api ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dubbo-api ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ dubbo-api ---
[INFO] Building jar: D:\zlq\zoom_eclipse\li\dubbo-api\target\dubbo-api-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ dubbo-api ---
[INFO] Installing D:\zlq\zoom_eclipse\li\dubbo-api\target\dubbo-api-1.0-SNAPSHOT.jar to D:\zlq\zoom_maven\m2\repository\com\demo\dubbo\dubbo-api\1.0-SNAPSHOT\dubbo-api-1.0-SNAPSHOT.jar
[INFO] Installing D:\zlq\zoom_eclipse\li\dubbo-api\pom.xml to D:\zlq\zoom_maven\m2\repository\com\demo\dubbo\dubbo-api\1.0-SNAPSHOT\dubbo-api-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.908 s
[INFO] Finished at: 2019-04-11T10:01:52+08:00
[INFO] ------------------------------------------------------------------------
搞定