IDEA启动Tomcat,控制台中文乱码

现象一

IDEA中启动Tomcat,控制台出现Tomcat自身打印日志的中文乱码。

IDEA版本:2021.3.2

Tomcat版本:10.0.14


解决方式

  1. IDEA菜单栏 - Help - Edit Custom VM Options…

    Edit Custom VM Options...

  2. 在文件中添加-Dfile.encoding=UTF-8后保存

    添加-Dfile.encoding=UTF-8

  3. 菜单栏 - File - Invalidate Caches…

  4. 直接选择Invalidate and Restart


现象二

java的输出语句如System.out.println(),在控制台显示为中文乱码。


解决方式

  1. Edit Configurations...

    Edit Configurations...

  2. 具体的Tomcat Server - Server - VM options:

    填入-Dfile.encoding=UTF-8后,OK并重启Tomcat即可生效。


参考

IDEA启动tomcat控制台出现中文乱码问题完美解决方案