場景描述:
代碼中使用JUnit編寫測試代碼,有中文輸出。在使用maven執行測試運行時,即執行maven test命令,控制檯中文亂碼
解決方案:
方式一:項目pom.xml中增加
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
主要是argLine那行,-Dfile.encoding=UTF-8。
之後只要正常執行命令即可
mvn test
方式二:若是不想修改pom.xml文件,只在命令行中執行,則可執行
mvn test -Dfile.encoding=UTF-8