Home >Java >javaTutorial >Problems encountered when maven integrates the framework with mybaits
First, let’s take a look at the standard directory structure of the MAVENx project:
Generally, the resource files we use (various xml , properties, xsd files, etc.) are placed under src/main/resources. When using maven for packaging, maven can package these resource files into the corresponding jar or war.
Sometimes, for example, the mapper.xml file of mybatis, we are used to putting it together with Mapper.java, both under src/main/java. In this way, when using maven to package, You need to modify the pom.xml file to package the mapper.xml file into a jar or war. Otherwise, these files will not be packaged. (Maven thinks that src/main/java is just the source code path of java). There are many methods on the Internet. I tried it out, and several methods are available. You can choose any one.
Method 1, where **/* is written in order to ensure that resource files in subdirectories at all levels are packaged.
xml code
<build> <finalname>test</finalname> <!-- 这样也可以把所有的xml文件,打包到相应位置。 <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.tld</include> </includes> <filtering>false</filtering><--这里是false,用true会报 数据库连接 错误--> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.tld</include> </includes> <filtering>false</filtering> </resource> </build>
Method 2, using the build-helper-maven-plugin plugin
The above is the detailed content of Problems encountered when maven integrates the framework with mybaits. For more information, please follow other related articles on the PHP Chinese website!