Failed to Build Application Getting Error::No toolchain found for type jdk

Failed to Build Application Getting Error::No toolchain found for type jdk

我为此尝试了不同的解决方案,但对我没有用,

请查看错误日志和 toolchain.xml 文件。

这些是错误日志:

[INFO] --- maven-toolchains-plugin:1.1:toolchain (default) @ ad-api ---
[INFO] Required toolchain: jdk [ vendor='sun' version='1.8' ]
[ERROR] No toolchain found for type jdk
[ERROR] Cannot find matching toolchain definitions for the following toolchain types:
jdk [ vendor='sun' version='1.8' ]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.619 s
[INFO] Finished at: 2018-10-05T08:56:24+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-toolchains-plugin:1.1:toolchain (default) on project ad-api: Cannot find matching toolchain definitions for the following toolchain types:
[ERROR] jdk [ vendor='sun' version='1.8' ]
[ERROR] Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file.
[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

将 1.8 版更新为 jdk1.8._172

时出现上述错误

下面是我的pom.xml

 <plugins>

   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
   </plugin>

   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-toolchains-plugin</artifactId>
      <executions>
         <execution>
            <goals>
               <goal>toolchain</goal>
            </goals>
         </execution>
      </executions>
      <configuration>
         <toolchains>
            <jdk>
               <version>jdk1.8.0_172</version>
               <vendor>sun</vendor>
            </jdk>
         </toolchains>
      </configuration>
   </plugin>

   <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <configuration>
         <encoding>${project.build.sourceEncoding}</encoding>
      </configuration>
   </plugin>

</plugins>

并且我在 toolchain.xml

中定义了 jdk 路径
<toolchains>
    <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.8</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>C:\Program Files\Java\jdk1.8.0_172</jdkHome>
    </configuration>
  </toolchain>
</toolchains>

请帮忙解决问题。 提前致谢。

将pom中的版本改为1.8而不是jdk1.8。0_172

                <configuration>
                    <toolchains>
                        <jdk>
                            <version>1.8</version>
                            <vendor>sun</vendor>
                        </jdk>
                    </toolchains>
                </configuration>

仔细检查您的目录路径。关于文件位置和使用 maven --toolchains C:\User\zzz\.m2\toolchains.xml clean install 进行测试的两条评论帮助我看到我的文件夹是“m2”而不是“.m2”。