Cosmic Flow Cosmic Flow - 29 days ago 36
Java Question

How to better setting up JVM encoding properties to UTF-8

When I trying package project with Maven, I receive this

...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
...

2017-09-23 14:00:11.447 ERROR 11468 --- [ main] o.s.b.c.FileEncodingApplicationListener : System property 'file.encoding' is currently 'Cp1252'. It should be 'UTF-8' (as defined in 'spring.mandatoryFileEncoding').
2017-09-23 14:00:11.464 ERROR 11468 --- [ main] o.s.b.c.FileEncodingApplicationListener : Environment variable LANG is 'null'. You could use a locale setting that matches encoding='UTF-8'.
2017-09-23 14:00:11.464 ERROR 11468 --- [ main] o.s.b.c.FileEncodingApplicationListener : Environment variable LC_ALL is 'null'. You could use a locale setting that matches encoding='UTF-8'.
2017-09-23 14:00:11.802 ERROR 11468 --- [ main] o.s.boot.SpringApplication : Application startup failed

java.lang.IllegalStateException: The Java Virtual Machine has not been configured to use the desired default character encoding (UTF-8).


It can be fixed like: add Environment variable
JAVA_TOOL_OPTION
=
-Dfile.encoding="UTF-8"
but it don't works.

Environment variable

In IntelliJ Idea Settings everything is set to UTF-8.

aplication.properties

spring.mandatory-file-encoding=UTF-8


pom.xml

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<file.encoding>UTF-8</file.encoding>
<java.version>1.8</java.version>
</properties>


Using Windows 10.

Answer Source

we can encode the source encoding and output encoding through adding line in properties section in pom.xml or by passing as a runtime arguments to command as follows :

mvn -Dproject.build.sourceEncoding=UTF-8  -
   Dproject.reporting.outputEncoding=UTF-8 clean deploy 

or by adding line in pom.xml

 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <redis.version>1.3.5.RELEASE</redis.version>
    </properties>