title: 解决Gradle、Maven项目build后没有mybatis的mapper.xml文件问题
date: 2019-05-31 21:09:59
categories:

  • Java
    tags:
  • 工具

GradleMaven都默认只把resources目录当作资源目录,所以在编译时就不会把java目录下的mapper.xml文件编译到输出目录,所以需要在相关文件中修改默认资源目录。Maven

  • pom文件中加入

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
    
  • Gradle

  • 在build.gradle文件中加入

    sourceSets {
    main {
    resources.srcDirs = ['src/main/resources', 'src/main/java']
    resources.includes = ['src/main/java/**.xml']
    }
    }