maven項目build時出現 No compiler is provided in this environment.錯誤

今天創建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,至此該問題就解決了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章