maven maven-surefire-plugin的乱码问题
今天项目中出现奇怪问题,在eclipse中直接运行TestNG时,全部都OK,但是执行mvn test时却失败.观察其输出日志,发现有乱码,怀疑是乱码导致.
最终在官网发现蛛丝马迹.
maven-surefire-plugin是运行mvn test时执行测试的插件,其有一个配置参数forkMode,默认为once,即表示每次运行test时,新建一个JVM进程运行所有test.这可能会导致乱码问题.首先将forkMode设置为never,即不新建.再运行mvn test,全部OK了.果然是这个问题!!
于是再找官方参数说明,发现了argLine参数,这个参数与forkMode一起使用,可以设置新建JVM时的JVM启动参数,于是设置<argLine>-Dfile.encoding=UTF-8</argLine>,明确指定一下JVM的file.encoding,并将forkMode从never改回once,还是每次新建一个JVM进程.再次运行mvn test,一起OK了,问题解决.
究其原因,是因为MAVEN的maven-surefire-plugin在新建JVM进程后,由于没有指定encoding,采用了OS的默认编码,导致读取UTF-8文件(测试类的sql脚本文件)时出现乱码,最终影响了TestNG的正确执行.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<!--<skipTests>true</skipTests>-->
</configuration>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<fork>true</fork>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<destFile>target/jacoco-unit.exec</destFile>
<dataFile>target/jacoco-unit.exec</dataFile>
<excludes>
<exclude>**/entity/**</exclude>
<exclude>**/mapper/**</exclude>
<exclude>**/exception/**</exclude>
<exclude>**/*Application.class</exclude>
<exclude>**/*Builder.class</exclude>
<exclude>**/*BO.class</exclude>
<exclude>**/*DO.class</exclude>
<exclude>**/*DTO.class</exclude>
<exclude>**/*VO.class</exclude>
</excludes>
<!--<includes>
<include>**/service/**</include>
<include>**/controller/**</include>
</includes>-->
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!--这个check:对代码进行检测,控制项目构建成功还是失败-->
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
<!--这个report:对代码进行检测,然后生成index.html在 target/site/index.html中可以查看检测的详细结果-->
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<!--<skipTests>true</skipTests>-->
</configuration>
</plugin>
</plugins>
</build>
maven maven-surefire-plugin的乱码问题的更多相关文章
- maven surefire plugin介绍
示例 <!-- 测试运行器,生成测试报告 --> <plugin> <groupId>org.apache.maven.plugins</groupId> ...
- Maven系列--"maven-compiler-plugin"的使用、Maven之Surefire插件
一."maven-compiler-plugin"的使用 http://my.oschina.net/poorzerg/blog/206856 二.Maven之Surefire插件 ...
- [转]解决Maven报错"Plugin execution not covered by lifecycle configuration"
[转]解决Maven报错"Plugin execution not covered by lifecycle configuration" 导入Myabtis源码后,POM文件会报 ...
- [Maven]Maven 那点事儿
0. 前言 Jason Van Zyl,在 Java 十大风云人物排行榜上或许会看到他. 这兄弟是干嘛的? 他就是 Maven 的创始人,人们都尊称他为"Maven 他爸". 毋庸 ...
- Maven - Maven速成
Maven Maven是一个项目构建和管理工具,有助于开发者快速完成项目的配置,快速建立开发环境,从而提高开发效率. 管理项目构建(build)的生命周期(清理.编译.测试.打包.发布.部署.报告等) ...
- 学习Maven之Maven Surefire Plugin(JUnit篇)
1.maven-surefire-plugin是个什么鬼? 如果你执行过mvn test或者执行其他maven命令时跑了测试用例,你就已经用过maven-surefire-plugin了.maven- ...
- maven集成tomcat插件以及乱码解决
Maven已经是Java的项目管理标配,如何在JavaEE开发使用Maven调用Web应用,是很多同学关心的问题.本文将介绍,Maven如何介绍Tomcat插件. Maven Tomcat插件现在主要 ...
- Maven assembly插件输出文件乱码问题
使用Maven的<artifactId>maven-assembly-plugin</artifactId>插件导致输出的XML配置文件源文件的中文注释变成乱码,排查了多个地方 ...
- maven编译,控制台中文乱码解决方案
如下图,在使用maven运行后,在控制台看到中文展示乱码 出现这个的原因是源码使用UTF-8,但是maven编译的时候使用GBK标准,如下图 为了让maven编译的时候使用UTF-8标准,使用在p ...
- 记一次Maven发布Jar包中文乱码解决方法
Maven deploy 乱码 今天使用Maven发布Jar包时,发布功能都是正常的也成功上传到了仓库,就是项目跑越来后出中文中现了乱码: { "code": "SUCC ...
随机推荐
- 使用 ref 获取另外组件的数据
- 立即报名 | AI +Serverless Meetup 上海站 8 月 5 日等你相约!
自 2021 年 5 月后,KubeSphere 社区与上海的各位小伙伴已阔别两年,许久不见,甚是想念!2023 年 8 月 5 日,KubeSphere 社区将走进上海组织一场主题为 "A ...
- 如何将rust日志输出到android终端
本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0许可协议.转载请注明来自 唯你 背景 在 Rust 中,使用 println!打印日志时,输出实际上是发送到标准输出(stdout),而 ...
- 一款 C# 编写的神经网络计算图框架
前言 深度学习技术的不断发展,神经网络在各个领域得到了广泛应用.为了满足 .NET 开发的需求,推荐一款使用 C# 编写的神经网络计算图框架. 框架的使用方法接近 PyTorch,提供了丰富的示例和详 ...
- .NET 8 强大功能 IHostedService 与 BackgroundService 实战
前言 在.NET 8中,IHostedService 和 BackgroundService 两个核心接口的引入,增强了项目开发中处理定时任务的能力.这两个接口不仅简化了定时任务.后台处理作业以及定期 ...
- 通过Java代码发送OutLook邮件
准备 我们想通过Java代码实现发送OutLook邮件,必须准备以下材料: OutLook邮箱 目标邮箱 查看OutLook邮箱信息 打开OutLook邮箱,在Settings中搜索或找到SMTP: ...
- 连接数据库报错的异常可以用mysqli_report来捕获
有时候数据库密码改了或者数据库删了,就会有一个mysqli的链接报错,是因为直接使用了类似代码 $connection = new mysqli('127.0.0.1', 'test_user', ' ...
- 服务器cli模式下的定时器
有时候需要一部分后台业务异步的处理,比如处理redis队列啊,处理mysql统计啊,数据同步啊,这种长时间任务,但是又需要每段时间去看看的,发现linux cron最小只能支持每分钟的任务 分 时 天 ...
- JConsole 远程监控Tomcat服务
JConsole 远程监控Tomcat服务 1.概述 JConsole是一个基于JMX的GUI工具,用于连接正在运行的JVM,不过此JVM需要使用可管理的模式启动.如果要把一个应用以可管理的形式启动, ...
- Integrating JDBC with Hibernate
One of the powerful things about Hibernate is that you do not typically need to manually write SQL: ...