今天创建maven项目build时出现”[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?“我很郁闷,以前创建普通项目时没有遇到这个问题啊,为什么创建maven项目时却会创想JDK的问题呢?
错误信息如下:
[INFO] Scanning for projects... [INFO] [INFO] -------------------------< Promaven:Promaven >-------------------------- [INFO] Building Promaven 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Promaven --- [INFO] Deleting D:\javacode\eclipseworkspaces\Promaven\target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Promaven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Promaven --- [WARNING] The POM for org.apache.maven:maven-plugin-api:jar:2.2.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details [WARNING] The POM for org.apache.maven:maven-core:jar:2.2.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details [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:\javacode\eclipseworkspaces\Promaven\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.761 s [INFO] Finished at: 2020-03-05T20:23:07+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Promaven: 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
其中我们不难发现有这样的信息:
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
中文的意思是:
此环境中不提供编译器。也许您运行的是JRE而不是JDK?
打开conf文件下的配置文件setting.xml文件我们会发现这样的一段说明:
<!-- profile | Specifies a set of introductions to the build process, to be activated using one or more of the | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | or the command line, profiles have to have an ID that is unique. | | An encouraged best practice for profile identification is to use a consistent naming convention | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | This will make it more intuitive to understand what the set of introduced profiles is attempting | to accomplish, particularly when you only have a list of profile id's for debug. | | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. <profile>
在上面信息的倒数第二行发现:这个概要文件示例使用JDK版本触发激活,并提供一个特定于JDK的repo
也就是说我们需要指定一个符合配置的JDK环境
依次如下做:
1,Window–>preferences–>Java–>Installed JREs–>installed JREs -->add -->standard VM --next.
2,之后进入JRE Definition界面,点击Directory…选择安装的JDK目录后面的的会自动添加,点击finish就可以了
注意因为我的已经配置了所以显示:the JRE is already in use.
3,选择jdk
4,右击项目–>Build Path–>configure Build Path…
5,选择Java build Path -->双击JRE System…–>选择你JDK相对应的版本。
6,至此该问题就解决了。