在Maven项目中添加代码目录下的配置文件
问题
Maven 是约定大于配置的一种工具, 通常约定在 src/main/resources 目录下放配置文件, 当我们想要在 src/main/java 代码目录下放置配置文件用来测试, Maven 项目 build 的时候并不会把代码目录下的配置文件添加到相应的位置, 可以查看 target 目录来证实这个情况, 最终会导致测试代码报错, 无法找到相应的配置文件.
解决方案
在 pom.xml 中配置 Maven 项目 build 时所需要的资源路径并开启过滤, 样例如下:
<project>
...
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
在Maven项目中添加代码目录下的配置文件的更多相关文章
- maven项目中,lib目录下有自己私有的包,则需要配置一下代码,然后进行打包
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compi ...
- Intellij IDEA在maven项目中添加外部Jar包运行
一. 问题概述 我们知道Intellij IDEA是非常好用的Java语言开发的集成环境.提供了非常多实用的功能,包括了智能代码助手.代码自动提示.代码重构.各种插件等,当然也集成了maven 正常情 ...
- IDEA将Maven项目中指定文件夹下的xml等文件编译进classes
eclipse下面创建的Maven项目,使用mybatis.eclipse里面能正常启动,在idea中一直卡在maybatis 加载位置. 1.首先是不报错也没反应.这个时候需要我们重写SqlSess ...
- maven项目中添加Tomcat启动插件
在pom.xml文件中添加如下配置: <!-- 配置tomcat插件,pom.xml里配置 --> <build> <plugins> <plugin> ...
- Maven项目中添加JDBC驱动
在pom.xml配置文件中添加: <dependency> <groupId>mysql</groupId> <artifactId>mysql-con ...
- Maven 项目中 添加自己的jar包
mvn install:install-file -Dfile=java-bloomfilter-1.0.jar -DgroupId=com.sina -DartifactId=java-bl ...
- IDEA Maven项目中添加tomcat没有无artifact选项
IntelliJ使用 ##使用IntelliJ IDEA配置web项目时,选择Edit Configration部署Tomcat的Deployment可能会出现以下情况: 导致新手部署过程中摸不着头脑 ...
- java项目中读取src目录下的文件
private void getUser(String tmpfile){ Properties props = new Properties(); props.load(DbTask.class.g ...
- IDEA的maven项目中 静态文件编译的问题
IDEA的maven项目中,默认源代码目录下的xml等资源文件并不会在编译的时候一块打包进classes文件夹,而是直接舍弃掉. 如果使用的是Eclipse,Eclipse的src目录下的xml等资源 ...
随机推荐
- spring 管理事务配置时,结果 报错: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here这个异常
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not al ...
- AJ学IOS(12)UI之UITableView学习(上)LOL英雄联盟练习
AJ分享,必须精品 先看效果图 源代码 NYViewController的代码 #import "NYViewController.h" #import "NYHero. ...
- Eclipse版本控制
各版本的区别: 1.Eclipse IDE for Java Developers 是Eclipse的platform加上JDT插件,用来java开发的 2.Eclipse IDE for Java ...
- C. Primes and Multiplication
题目连接:https://codeforces.com/contest/1228/problem/C 题目大意:g(x,y)==y^k(其中y^k是X的最大可以整除因子) f(x,y)==g(x,p1 ...
- 3. JS生成32位随机数
function randomWord ( randomFlag,min,max ) { var str = " ", range = min, arr = ['0','1','2 ...
- [转+自]SSH工作原理
SSH工作原理 熟悉Linux的人肯定都知道SSH.SSH是一种用于安全访问远程服务器的网络协议.它将客户端与服务端之间的消息通过加密保护起来,这样就无法被窃取或篡改了.那么它安全性是如何实现的呢? ...
- Java环境下 selenium webDriver + chrome浏览器搭建与调试
一.首先下载selenium webDriver jar包,下载地址如下: http://selenium-release.storage.googleapis.com/index.html 二.下载 ...
- 十分钟搞懂Elasticsearch数字搜索原理
更多精彩内容请看我的个人博客或者扫描二维码,关注微信公众号:佛西先森 前言 Elasticsearch诞生的本意是为了解决文本搜索太慢的问题,ES会默认将所有的输入内容当作字符串来理解,对于字段类型是 ...
- beego微信网页授权
beego.Get("MP_verify_Rj3QAbcdU0MRsyS.txt", func(context *context.Context) { context.Respon ...
- input type file onchange上传文件的过程中,同一个文件二次上传无效的问题。
不要采用删除当前input[type=file]这个节点,然后再重新创建dom这种方案,这样是不合理的.解释如下:input[type=file]使用的是onchange去做,onchange监听的为 ...