Garbled characters appear when running java projects through bash/cmd
Question:
No matter how the Java code is uniformly encoded as UTF8, it is completely fine to run in the IDE, but it is packaged into Jar and run through Bash and CMD. , Chinese garbled characters will appear.
Reason:
The default encoding of cmd/bash is GBK.
Solution:
1. Set the cmd encoding to utf-8
Open cmd and enter the following command:
chcp 65001
This way You can change the encoding of cmd to UTF-8.
The following is the commonly used cmd encoding, as shown in the figure:
2. Specify the encoding method when executing java
Under cmd, The common commands to run Jar packages are as follows:
java -jar project.jar
However, this may cause errors caused by incorrect encoding during java runtime. At this time, we can specify the encoding parameters when running Jar
java -Dfile.encoding=utf-8 -jar project.jar
Three . Package the above commands into a bat
If you have to perform the above two steps every time you start the project, it will actually be very troublesome. We can package the above two steps into a bat batch file. The specific steps are as follows
3.1 Create a txt file in the Jar directory and open it with Notepad
3.2 Write the above command into the txt file and save it
3.3 Modify msgSystemStart.txt to msgSystemStart.bat
The above is the detailed content of Garbled characters appear when running java projects through bash/cmd. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool