Mapper.xml can't get in when Maven packs.

Source: Internet
Author: User

First, look at the directory structure of the MAVENX Project Standard:

In general, the resource files we use (various xml,properites,xsd files, etc.) are placed under Src/main/resources, and MAVEN can package these resource files into the appropriate jar or war using MAVEN.

Sometimes, such as MyBatis's Mapper.xml file, we used to put it and Mapper.java together, all under the Src/main/java, so using maven packaging, You will 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 Src/main/java is just Java's source code path). There are many methods on the network, I probably tried, several methods can be, can choose one.

Method 1, where **/* is written in order to ensure that the resource files under all levels of subdirectories are packaged.

XML code

<Build>    <Finalname>Test</Finalname>    <!--This also allows all XML files to be packaged in the appropriate location. <resources> <resource> <directory>src/main/resources</directory> < Includes> <include>**/*.properties</include> <include>**/*.xml</incl ude> <include>**/*.tld</include> </includes> <filtering>fa lse</filtering><--here is false, the database connection error is reported with true-</resource> <resource> < ;d irectory>src/main/java</directory> <includes> <include>**/*.properties< ;/include> <include>**/*.xml</include> <include>**/*.tld</include>            ; </includes> <filtering>false</filtering> </resource> </resources></b Uild>

Method 2, using the Build-helper-maven-plugin plugin

<Build>    ...    </Plugins>        ...        <!--This plugin can be used to take advantage of this plugin, the source code in the XML file, packaging to the appropriate location, here is mainly to package MyBatis Mapper.xml file -        <plugin>            <groupId>Org.codehaus.mojo</groupId>            <Artifactid>Build-helper-maven-plugin</Artifactid>            <version>1.8</version>            <executions>                <Execution>                    <ID>Add-resource</ID>                    <Phase>Generate-resources</Phase>                    <Goals>                        <goal>Add-resource</goal>                    </Goals>                    <Configuration>                        <Resources>                            <Resource>                                <Directory>Src/main/java</Directory>                                <includes>                                    <include>**/*.xml</include>                                </includes>                            </Resource>                        </Resources>                    </Configuration>                </Execution>            </executions>        </plugin>           ...    </Plugins>         ...</Build>

Method 3, using the Maven-resources-plugin plugin

<Build>    ...    </Plugins>        ...        <!--This plugin can be used to take advantage of this plugin, the source code in the XML file, packaging to the appropriate location, here is mainly to package MyBatis Mapper.xml file -        <plugin>            <Artifactid>Maven-resources-plugin</Artifactid>            <version>2.5</version>            <executions>                <Execution>                    <ID>Copy-xmls</ID>                    <Phase>Process-sources</Phase>                    <Goals>                        <goal>Copy-resources</goal>                    </Goals>                    <Configuration>                        <outputdirectory>${basedir}/target/classes</outputdirectory>                        <Resources>                            <Resource>                                <Directory>${basedir}/src/main/java</Directory>                                <includes>                                    <include>**/*.xml</include>                                </includes>                            </Resource>                        </Resources>                    </Configuration>                </Execution>            </executions>        </plugin>           ...    </Plugins>         ...</Build>

Reproduced in: http://bglmmz.iteye.com/blog/2063856

Mapper.xml can't get in when Maven packs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.