这似乎真的很疯狂,但我无法在 IntelliJ IDEA 的控制台中对损坏的编码执行任何操作。
我为克服这个问题所做的事情:
-Dfile.encoding=UTF-8
和-Dfile.encoding=UTF-8
中设置idea.exe.vmoptions
和idea64.exe.vmoptions
(不过我使用64位版本)。-Dfile.encoding=UTF-8
和 -Dfile.encoding=UTF-8
来运行/调试我的应用程序的配置。完成所有这些操作后,仍然没有运气,符号在控制台中没有正确显示。我尝试调试
java.io.PrintStream#println(java.lang.String)
方法,发现System.out.textOut.out.se.cs
等于windows-1251。不知道这个值从哪里来。
这个问题困扰了我很长时间,我在网上找不到任何可以帮助我的东西。
这对我有用。
尝试
-Dconsole.encoding=UTF-8
而不是
-Dfile.encoding=UTF-8
你可能修改了错误的文件,
不是:
C:\Program Files\JetBrains\IntelliJ IDEA xxxx\bin\idea64.exe.vmoptions
应该是:
C:\Users\USER_NAME\.IntelliJIdeaxxxx\config\idea64.exe.vmoptions
您可以同时添加
-Dfile.encoding=UTF-8
和 -Dconsole.encoding=UTF-8
IntelliJ IDEA 在内部使用操作系统的 shell 作为控制台。在 Windows 中,这是命令提示符。所以如果添加...
-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8
...到
Help -> Edit Custom VM Options
下的VM选项没有帮助,请确保您的shell首先支持UTF-8字符。
唯一对我有用的是设置环境变量 JAVA_TOOLS_OPTIONS 在win cmd下运行
setx JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8
然后重新启动 IDE。
就我而言,在调试中检查
System.out.textOut.out.se.cs
暗示 IDEA 为每个 JUnit 运行配置拾取了 Maven Surefire 参数:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- force 7-bit default encoding to ensure that nothing depends on it -->
<argLine>-Dfile.encoding=ASCII</argLine>
</configuration>
</plugin>
我通过将
-Didea.maven.surefire.disable.argLine=true
添加到 idea64.exe.vmoptions 文件解决了这个问题。
另请参阅:https://www.jetbrains.com/help/idea/configuring-output-encoding.html。
如果有人遇到过这个问题,并且在最上面的答案中没有任何作用,请尝试下载另一个 JDK 版本并在 SDK 中使用。
正如 @ogkasa 提到的,如果你遇到这样的问题并且没有任何帮助,只需尝试安装另一个 JDK 版本即可。我个人尝试了所有可能的解决方案,但没有一个有效。所以我刚刚回滚到 JDK 17,现在西里尔字母(这是我的问题)可以正常工作。
波兰语字母(波兰语文学)我通过@Vadzim's提示获得:
1。编辑POM.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.2</version>
</dependency>
</dependencies>
</plugin>
2。通过添加编辑idea64.exe.vmoptions文件
-Didea.maven.surefire.disable.argLine=true