Solve the problem that maven does not package xml files

  • 2021-12-11 17:40:30
  • OfStack

The directory maven does not package xml files. maven does not package xml files under resources when packaging

maven does not have the problem of packaging xml files

Recently, using maven tape management project, using SSM technology stack, after configuring 1 configuration file, packaging and deploying to tomcat, the configuration file of SpringMVC was not found, and the corresponding xml file was really not seen in the folder generated by viewing maven packaging.

Originally, it was required to add in the pom. xml file of maven


<build>
        <finalName>MobileSchool-chat</finalName>
 
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

In this way, xml can be packaged by repackaging.

xml files under resources are not packaged when maven is packaged

In maven project, when we use install command to type jar package, we sometimes need not package some files under resources, such as * Mapper. xml file generated by Mybatis, so as to overwrite with our newly generated files. At this time, we need to introduce maven-jar-plugin plug-in into the project.

Add the following configuration to the project's pom. xml file:


    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <!-- Exclude resources Folder -->
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-jar-plugin</artifactId>
               <configuration>
                  <excludes>
                     <!-- Note that this thing calculates the directory structure from the compilation result directory -->
                     <exclude>/mapping/**/*.xml</exclude>
                  </excludes>
               </configuration>
            </plugin>
        </plugins>
    </build>

With the above configuration, the xml files in the src/main/resources/mapping directory (including subdirectories) in the project will not be packaged into the generated jar package


Related articles: