Maven项目pom.xml的标签<resource>
Maven项目的标准目录结构
src
main
java 源文件
resources 资源文件
filters 资源过滤文件
config 配置文件
scripts 脚本文件
webapp web应用文件
test
java 测试源文件
resources 测试资源文件
filters 测试资源过滤文件
it 集成测试
assembly assembly descriptors
site Site
target
generated-sources
classes
generated-test-sources
test-classes
xxx.jar
pom.xml
LICENSE.txt
NOTICE.txt
README.txt
资源文件的配置
配置文件通常与.java文件一起放在src/main/java目录
有时候有些配置文件通常与.java文件一起放在src/main/java目录
有的时候还希望把其他目录中的资源也复制到classes目录中。
这些情况下就需要在Pom.xml文件中修改配置了,可以有两种方法:
一是在<build>元素下添加<resources>进行配置。
另一种是在<build>的<plugins>子元素中配置maven-resources-plugin等处理资源文件的插件。
<build>元素下添加<resources>进行配置

<build> <resources> <!-- 指定了java和resources下的xml文件,xlsx文件,xls文件打包到根目录 --> <resource> <directory>src/main/java</directory> <includes> <include>*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.yml</include> <include>**/*.properties</include> <include>**/*.xml</include> <include>*.xlsx</include> <include>*.xls</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> </resources> <plugins> <!--解决打包没有mainClass问题--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.2.6.RELEASE</version> <configuration> <fork>true</fork> <mainClass>com.power.app.AppWebApplication</mainClass> <includeSystemScope>true</includeSystemScope> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> <finalName>app-web</finalName> </build>
<build>的<plugins>子元素中配置maven-resources-plugin

<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>
来源 https://www.cnblogs.com/dreamroute/p/6729147.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
2020-02-21 Spring-data-jpa Repository写法
2020-02-21 JPA出现recursion 死循环导致栈内存溢出问题 Could not write JSON: Infinite recursion (StackOverflowError)
2019-02-21 Java Web安全问题及解决方案