Idea packaging will filter out configuration files (xml, properties) problems

Today, the Xxx is not mapped error occurred when using idea to import the project, but it was normal when eclipse was running. Later, it was found that there was no xml file for hiberante configuration in the compiled target file, so the pom.xml file was changed. modify. Reason: In IDEA's maven project, src/main/javathe xml and other resource files in the default source code directory ( directory) will not be packaged into the classes folder when compiling, but discarded directly. If you are using Eclipse, the xml and other resource files in the Eclipse src directory will be automatically packaged and output to the classes folder during compilation. When using maven for module development, the configuration file xml will be placed in the dao layer. When the idea is packaged, only the java file will be packaged, and some mapper mapping files or properties files will be filtered out, and the mapper configuration will not be found during deployment. File and other errors, the solution is to add the following configuration in the pom file:

<build>
  <!--配置打包时不过滤非java文件开始  -->
  <!--说明,在进行模块化开发打jar包时,maven会将非java文件过滤掉,
  xml,properties配置文件等,但是这些文件又是必需的,
  使用此配置可以在打包时将不会过滤这些必需的配置文件。
  -->
  <resources>
  	<resource>
  	    <directory>src/main/java</directory>
  	    <includes>
  	        <include>**/*.properties</include>  
                <include>**/*.xml</include>  
  	    </includes>
  	    <filtering>false</filtering>
  	</resource>
  	<resource>  
            <directory>src/main/resources</directory>  
            <includes>  
                <include>**/*.properties</include>  
                <include>**/*.xml</include>  
            </includes>  
            <filtering>false</filtering>  
        </resource>  
  </resources>
  <!--配置打包时不过滤非java文件结束 -->
</build>

 

Guess you like

Origin blog.csdn.net/QRcode_Y/article/details/106664963
Recommended