gradle + mybatis replication xml configuration file to the output directory, etc.

problem

After the deployment of the project and start the project, using mybatis time, reported an error: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)the project runs without any problems in eclipse, but the idea next time an error

the reason

After various Internet search found that the idea is in the process of compiling tool packaged, only handling src / main / java inside java files to the output directory, project or other configuration xml placed in src / main / java directory file handling is not carried out, which led to the existence of a configuration file can not be found

Solution one:

The configuration-related files back under the resource directory will be output to the next corresponding resource directory package

Solution two:

By configuring the gradle build configuration, in build.gradleaddition of the configuration:

sourceSets {
    main {
        resources {
            // all resources under the non-.java java catalog can be packed into classes under 
            srcdir ' src / main / java '
        }
    }
}

 

The above configuration will put all non-java resource file packaged under the resource directory, this configuration is compatible jar package packaging output, this scum, just a porter, the specific principle can go to see the document gradle
package jar package alone time We need to make the following configuration

apply plugin: 'java'
jar {
    from('src/main/java'){
        include '**/*.xml'
    }
}

 

If the wording srcDirs, then please note the following need to write, otherwise, you will find that this should be copied configuration file does not copy:

sourceSets {
    main {
        resources {
            // all non .java resources under the java directory can be packaged into the classes 
            srcDirs = [ ' the src / main / java ' , ' the src / main / Resources ' ]
        }
    }
}

 

SourceSets action is to solve the CI source code directory structure, for example, the configuration file directory is not src / main / resources directory, but the src / resources directory (less the main directory), then by the need to modify the above methods, replacing the default configuration file location. Of course, you can also modify the position of the source code directory by:

sourceSets {
    main {
        java{
            srcDir 'src/java'
        }
        resources {
            srcDir 'src/resources'
        }
    }
}

 

Remark

And why the eclipse there is no problem even if the pom, gradle do not do this particular configuration because the eclipse maven does not depend on the time of the build project pom, compile mechanism eclipse of gradle file does not ignore the xml source file folder inside

Reference [ https://blog.csdn.net/yin138/article/details/79181228 ]



Guess you like

Origin www.cnblogs.com/Im-Victor/p/11004650.html