IDEA does not compile the xml file in the java directory of src and its solution

In IDEA's maven project, the xml and other resource files in the default source code directory (src/main/java directory) will not be packaged into the classes folder during compilation, but will be discarded.

The first method : If there is no special business and you do not need to specify the resource file to be located under src/main/java, you can create a main/resources directory under src and place the required xml resource file in it. By default, the maven tool will package the resource files in the resources folder into the classes directory when compiling.

The second method : configure maven's pom file configuration, find the node in the pom file, and add the following code:

<build>  
  <resources>  
    <!-- mapper.xml文件在java目录下 -->
    <resource>  
      <directory>src/main/java</directory>  
        <includes>  
          <include>**/*.xml</include>  
        </includes>  
    </resource>  
  </resources>  
</build>

Note that it must be particularly emphasized here. If you don't follow the src/main/java directory structure, idea can be automatically compiled. If you use spingmvc, you also need to register static resources such as pictures in the mvc configuration file:

<mvc:resources mapping="/assets/**" location="/assets/" />

Guess you like

Origin blog.csdn.net/u011930054/article/details/101021542