解决Maven静态资源过滤问题
作者:Andy1357 时间:2023-04-27 21:04:53
软件版本:
IDEA 2020.1
Maven 3.6.3
认识静态资源和动态资源
静态资源,包含HTMl,图片,CSS,JS等不需要与数据库交互的一类文件
动态资源:需要与数据库交互,可以根据需要显示不同的数据,不需要修改页面
问题描述
在src或其子文件夹下写了配置文件却无法被导出到target, 导致程序发生错误无法执行
写这个博客的时候是在mybatis配置的过程中遇到的问题, 以前也遇到过, 索性写下来趴
解决步骤
在pom.xml中加入
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
Tip: 如果你的目录结构或静态资源类型与上面的不同, 请随机应变
clean一下去掉原来的target
重新运行程序
Tip: 如果遇到IDEA编码不对提示一堆UTF-8的情况, 去Settings里面改一下编码即可
结局
参考
http://maven.apache.org/guides/getting-started/index.html#how-do-i-filter-resource-files
https://blog.csdn.net/weixin_39206909/article/details/109484178
来源:https://blog.csdn.net/jasonbrook/article/details/110481203
标签:Maven,静态资源,过滤
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java使用正则表达校验手机号码示例(手机号码正则)
2022-04-07 20:37:04
android View 绘制完成监听的实现方法
2023-08-06 20:47:05
C#获取进程和对进程的操作
2021-07-14 19:50:35
![](https://img.aspxhome.com/file/2023/4/98194_0s.png)
Android自定义View实现验证码
2021-11-08 01:13:31
![](https://img.aspxhome.com/file/2023/2/138872_0s.jpg)
Java将对象保存到文件中/从文件中读取对象的方法
2022-06-18 21:26:42
Java线程安全中的有序性浅析
2023-07-12 03:07:58
![](https://img.aspxhome.com/file/2023/4/96114_0s.png)
java控制台输入示例分享
2023-11-28 02:28:05
QT实现简单计算器功能
2021-08-19 21:47:19
![](https://img.aspxhome.com/file/2023/9/127539_0s.jpg)
Android 去掉状态栏的方法汇总
2022-05-25 01:31:18
java多线程读取多个文件的方法
2022-12-05 04:37:45
Java多线程锁机制相关原理实例解析
2023-05-25 12:33:37
![](https://img.aspxhome.com/file/2023/0/96110_0s.png)
Android RecyclerView实现水平、垂直方向分割线
2023-07-24 15:40:35
![](https://img.aspxhome.com/file/2023/1/91661_0s.jpg)
Java并发编程之浅谈ReentrantLock
2022-08-25 10:46:02
![](https://img.aspxhome.com/file/2023/5/91735_0s.png)
java实现ip地址与十进制数相互转换
2022-08-10 17:39:31
Java设计模式--代理模式
2023-02-26 21:45:32
![](https://img.aspxhome.com/file/2023/5/64885_0s.jpg)
Java面试synchronized偏向锁后hashcode存址
2023-08-09 09:15:06
![](https://img.aspxhome.com/file/2023/0/57920_0s.png)
Android之PreferenceActivity应用详解
2023-03-28 14:26:37
![](https://img.aspxhome.com/file/2023/9/138199_0s.jpg)
Android操作系统之内存回收策略
2021-09-26 06:38:01
java使用Jsoup组件生成word文档
2022-10-28 12:44:16
Android 拦截返回键事件的实例详解
2023-02-19 07:09:09