java unmappable character for encoding

Nowadays, many projects contain Java source code that is  UTF-8 encoded, which allows you to add special characters like €, Chinese, Korean, Japanese characters, etc into your Java source code. But this brings a problem when compiling the code in Windows platform.

java unmappable character for encoding GBK (or CP1252)

If you are using Gradle, the quick fix is to add the following lines into build.gradle file

compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

Alternatively, you can set up a system/environment variable

JAVA_TOOL_OPTIONS

If you set this variable to -Dfile.encoding=UTF8, everytime a JVM is started, it will use the proper encoding.

System Variable

(Visited 15 times, 1 visits today)

Leave a Reply