Maven 单测使用资源文件(词表、配置等)及资源文件损坏
2018-03-28 10:57
330 查看
pom.xml加入:<build>
...... 其他项,此处省略
<testResources>
<testResource>
<directory>conf</directory>
</testResource>
<testResource>
<directory>model</directory>
</testResource>
</testResources>
...... 其他项,此处省略
</build>最后工程根目录下的conf和model目录中的文件/文件夹会拷贝到${project.build.directory}/test-classes下。
单测中加入:URL url = Thread.currentThread().getContextClassLoader().getResource("mojo/gbm_mojo_test.zip");
String modelPath = url.getPath();则可获取到对应的文件路径。
切记,pom中,千万不要加入<filtering>true</filtering>标签,否则资源文件会被改写,上例中zip文件将损坏导致无法解压。可详见:https://blog.csdn.net/hzzhoushaoyu/article/details/47207515
...... 其他项,此处省略
<testResources>
<testResource>
<directory>conf</directory>
</testResource>
<testResource>
<directory>model</directory>
</testResource>
</testResources>
...... 其他项,此处省略
</build>最后工程根目录下的conf和model目录中的文件/文件夹会拷贝到${project.build.directory}/test-classes下。
单测中加入:URL url = Thread.currentThread().getContextClassLoader().getResource("mojo/gbm_mojo_test.zip");
String modelPath = url.getPath();则可获取到对应的文件路径。
切记,pom中,千万不要加入<filtering>true</filtering>标签,否则资源文件会被改写,上例中zip文件将损坏导致无法解压。可详见:https://blog.csdn.net/hzzhoushaoyu/article/details/47207515
相关文章推荐
- 资源文件配置和使用
- 使用XML读写删除功能来实现资源文件配置
- Linux资源使用配置文件 /etc/security/limits.conf
- maven2之m2eclipse使用手册之一简介与配置文件settings.xml
- 专业版Unity技巧分享:使用定制资源配置文件
- [使用心得]maven2之m2eclipse使用手册之一简介与配置文件settings.xml
- 资源文件配置和使用
- 专业版Unity技巧分享:使用定制资源配置文件
- 使用coffeescript-maven-plugin,实时监控coffee文件的编译,只需一步配置
- 使用maven为不同环境打包资源文件
- 使用lesscss-maven-plugin,实时监控less文件的编译,只需一步配置
- 资源文件配置和使用
- 使用maven属性变量和配置文件
- 使用Spring中Src下 -context.xml : 用资源文件夹保存数据库的链接信息 并在配置文件里读取
- 利用配置文件使用一些可配置的资源
- 专业版Unity技巧分享:使用定制资源配置文件 ScriptableObject
- 大型Java项目中使用maven进行管理,pom.xml文件中build的配置
- maven: 开发、测试和生产环境使用不同的配置文件例子
- 资源文件配置和使用
- puppet安装与使用--配置文件及常用资源