maven默认src下的xml,properties文件不打包到classes文件夹下

一、第一种是建立src/main/resources文件夹,将xml,properties等资源文件放置到这个目录中。maven工具默认在编译的时候,会将resources文件夹中的资源文件一块打包进classes目录中。

这时候注意把resources设置成resource目录,已经是就不用管了。

二、第二种解决方式是配置maven的pom文件配置,在pom文件中找到<build>节点,添加下列代码:

<build>

<resources>

<resource>

<!-- 这里是放在 src/main/java-->

<directory>src/main/resources/fxml</directory>

<includes>

<include>**/*.properties</include>

<!-- **/表示只要在资源目录下的.json文件都被加载到classes文件中,

不管是否在资源目录子目录中-->

<include>**/*.json</include>

<include>**/*.xml</include>

<include>**/*.fxml</include>

<include>**/fxml/*.fxml</include>

<!-- 如果想要弄个包名专门放fxml文件,像上一行这样添加设置 -->

<!-- 之后,使用getResource("fxml/xx.fxml")这样子 -->

</includes>

<filtering>false</filtering>

</resource>

</resources>

</build>

相关推荐
莫逸风14 小时前
【AgentScope 2.0】 0. 学习指南
java·llm·agent·agentscope
z1234567898615 小时前
2026最新两款AI编程工具深度对比实测
java·数据库·ai编程
yaoxin52112315 小时前
470. Java 反射 - Member 接口与 AccessFlag
java·开发语言·python
做个文艺程序员15 小时前
Linux第24篇:Java应用监控体系搭建:Prometheus+Grafana可视化运维
java·grafana·prometheus
小钻风336616 小时前
Spring Boot 文件上传详解:深入理解 MultipartFile 的使用与原理
java·开发语言
其美杰布-富贵-李16 小时前
Spring Boot 工程开发全流程说明
java·spring boot·后端
前端双越老师18 小时前
如何以前端视角(非0基础)学 Java ?
java·node.js·全栈
dear_bi_MyOnly18 小时前
【SpringBoot配置文件】
java·spring boot·后端·学习·spring·java-ee·学习方法
做个文艺程序员18 小时前
Linux第22篇:用Docker容器化你的Java SaaS应用:一次构建,随处运行
java·docker·容器
其美杰布-富贵-李19 小时前
Spring Boot 依赖注入说明文档
java·spring boot·python