About the processing of No compiler is provided in this environment when the Maven project is built

ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? I
thought this was an isolated case, caused by a careless colleague and a problem with the configuration environment. There are not a few people who have come to this problem, but the explanation of the problem does not mention the root cause, so I wrote this blog for your reference. If there are any mistakes, please correct me.

Error code excerpt:

[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: 1.436 s
[INFO] Finished at: 2017-06-28T11:16:07+08:00
[INFO] Final Memory: 10M/151M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project manage: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]

However, it is normal to compile and run an ordinary Java Project. The following figure shows an ordinary java class with only output statements.

As can be seen from the above figure, the java compilation environment is in jre1.7.0_17, that is to say, it is not configured as a jdk directory, then look at Eclipse–>Window–>preferences–>Java–>Installed JREs
write picture description here

In order to demonstrate the effect, before the test, I have configured the system java environment to the path shown in the figure above, and only keep this configuration. As can be seen from the figure below, the path is one of the two JDK versions I have installed. The jre runtime environment that comes with JDK. There is no problem in compiling ordinary projects using this environment, but why is there an error when compiling Maven projects?

Let's see how the Maven environment is configured: first find Eclipse–>Window–>preferences–>Maven–>Installations
write picture description here
In the Maven configuration, I did not use the Maven plugin that comes with Eclipse, but the reconfigured Maven environment, Then look at Eclipse–>Window–>preferences–>Maven–>User Settings
write picture description here

Maven settings use settings.xml under the conf folder in Maven, click "open file" to view the specific configuration information in Eclipse, and only extract the parts related to this error message

  <profiles>
    <!-- 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>
        <id>jdk-1.7</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.7</jdk>
        </activation>
        <properties>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
            <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
        </properties>
    </profile>
  </profiles>

For the understanding of the specific information in the middle, you can refer to the blog of Glacier winner. That is to say, according to the above configuration, we need to specify a JDK environment that meets the configuration, which is what we did in Eclipse–>Window–>preferences–>Java–>Installed The configuration under JREs will not work, and you need to specify a JDK directory, such as jdk1.7.0_17 in my JDK installation directory, which is also the culprit of this error. However, for Java developers, Installed JREs use jdk directory instead of the jre directory is also the best option.

Configuration steps:
write picture description here

write picture description here
write picture description here
https://img-blog.csdn.net/20170628131756359?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHNsazk4OTg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEastwrite picture description here
write picture description here
write picture description here
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325471914&siteId=291194637