You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows PowerShell中Maven测试输出的Emoji编码问题(VSCode/IntelliJ)

解决Windows PowerShell中Maven输出Emoji乱码的问题

方法1:切换PowerShell控制台编码为UTF-8

PowerShell默认控制台编码可能不是UTF-8,导致Emoji输出乱码,先临时切换编码试试:

  • 在PowerShell中执行命令:

    chcp 65001
    

    切换后再运行mvn test或./mvnw test查看效果。

    若要永久设置,可按以下步骤操作:

    • 右键PowerShell快捷方式→属性→选项标签页,将“当前代码页”修改为65001;
    • 或者通过注册表修改(操作前注意备份):打开注册表编辑器,定位到HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe,新建字符串值CodePage,设置值为65001。

方法2:补充Maven的JVM编码参数

你之前加的编码参数可能不够,补充-Dconsole.encoding=UTF-8参数,完整命令如下:

./mvnw test -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -Dconsole.encoding=UTF-8

如果不想每次都输参数,可修改Maven的settings.xml文件(路径通常为~/.m2/settings.xml或Maven安装目录下的conf/settings.xml),添加编码配置:

<profiles>
  <profile>
    <id>utf8-encoding</id>
    <properties>
      <file.encoding>UTF-8</file.encoding>
      <sun.stdout.encoding>UTF-8</sun.stdout.encoding>
      <sun.stderr.encoding>UTF-8</sun.stderr.encoding>
      <console.encoding>UTF-8</console.encoding>
    </properties>
  </profile>
</profiles>
<activeProfiles>
  <activeProfile>utf8-encoding</activeProfile>
</activeProfiles>

方法3:改用Windows Terminal运行PowerShell

原生PowerShell的编码和Emoji支持有限,Windows Terminal对UTF-8和特殊字符的兼容性更好。安装Windows Terminal后,在其中打开PowerShell执行Maven命令,通常能正常显示Emoji。


内容的提问来源于stack exchange,提问作者Page not found

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 11:56:01