When running Jar, the Chinese logs output on the console are all garbled characters. This is because the default encoding of cmd/bash is GBK. Just change the encoding of cmd to UTF-8.
Two ways to modify: temporary modification and registry permanent modification
Temporary modification
It is only valid for the current cmd page, and it will be restored to GBK after closing and reopening.
Open cmd and enter the following command
chcp 65001
In this way, the encoding of cmd can be changed to UTF-8.
The following are commonly used cmd codes
Character Encoding |
corresponding character |
GBK (default) |
936 |
American English |
437 |
utf-8 |
65001 |
At this time, we can specify the encoding parameters when running the Jar
java -Dfile.encoding=utf-8 -jar project.jar
It's back to normal now
For convenience, you can also modify the code and run the jar service into a bat file, and click to run it next time
chcp 65001
java -Dfile.encoding=utf-8 -jar project.jar
permanent modification
(1) win key + R, enter regedit , confirm
(2) Find HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor in order
(3) Right-click - New, select "String Value", name it "autorun", right-click to modify, fill in "chcp 65001" for the value data, and confirm
Opening cmd at this time has defaulted to utf8
There is no garbled code