4

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.

Community
  • 1
  • 1
Ally
  • 61
  • 2
  • 7
  • is any of these properties used in `maven-compiler-plugin`? – Naman Sep 23 '17 at 11:55
  • No they are not used by maven-compiler-plugin. `java.version` is used by spring-boot but only if you use the spring boot parent. Otherwise it does not work that way... – khmarbaise Sep 23 '17 at 14:29

3 Answers3

3

We can encode the source encoding and output encoding by passing 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>
SilverNak
  • 3,283
  • 4
  • 28
  • 44
Raja Bose
  • 344
  • 2
  • 8
  • Setting the encoding via command line `project.build.sourceEncoding` is already done via the properties via properties area in pom file..no need to do that another time on command line. The most important one is to set the file-encoding... – khmarbaise Sep 23 '17 at 14:30
0

Can you try specifying it as a command line argument, e.g.:

java -Dfile-encoding=UTF-8 -jar yourfile.jar
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
0
mvn test -Dfile.encoding=UTF-8