No compiler is provided in this environment when you build maven project. Error

Today, when you create a maven project build "[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?" I was very depressed, did not encounter this problem when you create a common project before ah, why create Shique maven project will create problems JDK think of it?

The following error message:


[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

Which is not difficult to find such information:

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Chinese means:
this environment does not provide a compiler. Perhaps you are running JRE instead of JDK?

Open the configuration file in the conf file setting.xml file we will find such a description:

<!-- 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>
    

In the penultimate line of the above information is found: This example uses the JDK version profile trigger is activated, and to provide a specific JDK's repo
means we need to specify a configuration consistent with the JDK environment
in order to do the following:
1, Window-> the Preferences -> Java-> Installed JREs-> installed JREs -> add -> standard VM --next.
Here Insert Picture Description

2, after entering the JRE Definition screen, click Directory ... behind the choice of JDK installation directory will be automatically added, you can click finish the
Here Insert Picture Descriptionnote because I have configured so the display: the JRE is already in use.

3, select the JDK
Here Insert Picture Description
4, right-click Project -> Build Path-> configure Build Path ...

Here Insert Picture Description
5. Select the Java build Path -> Double-click the JRE System ... -> Choose your JDK corresponding version.
Here Insert Picture Description6, thus the problem is solved.

Published 32 original articles · won praise 24 · views 5899

Guess you like

Origin blog.csdn.net/qq_43663493/article/details/104683227