mvn编译“Cannot find matching toolchain definitions for the following toolchain types“报错解决方法

    科技2025-08-05  22

    问题

    git clone https://github.com/apache/shiro.git git checkout shiro-root-1.2.4 cd ./shiro/samples/web

    在编译demo时,遇到报错:

     Cannot find matching toolchain definitions for the following toolchain types: [ERROR] jdk [ vendor='sun' version='1.7' ] [ERROR] Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file.

    解决方法

    1 修改mvn配置文件

    配置文件路径

    修改内容为,本地的jdk的java_home,以及对应jdk版本,注意这里可以写多个jdk版本,只要本地有:

    <toolchain> <type>jdk</type> <provides> <version>1.8</version> <vendor>sun</vendor> </provides> <configuration> <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/</jdkHome> </configuration> </toolchain>

    2 检测项目pom文件:

    搜索toolchains,修改对应版本为刚才mvn的配置文件中指定一个版本,这里必须是刚才配置的jdk版本中有的版本

    3 mvn package

    Processed: 0.009, SQL: 8