2017-09-23 25 views
2

當我試圖使用Maven包項目,我收到此如何JVM編碼屬性更好的設置爲UTF-8

... 
------------------------------------------------------- 
    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). 

它可以固定,如:添加環境變量JAVA_TOOL_OPTION = -Dfile.encoding="UTF-8"但不作品。

Environment variable

在IntelliJ IDEA的設置一切被設置爲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> 

使用Windows 10

+0

是任何這些性質在'行家編譯-插件使用的'? – nullpointer

+0

不,它們沒有被maven-compiler-plugin使用。 ''versionversion'被spring-boot使用,但只有在你使用spring boot parent時。否則它不會這樣工作... – khmarbaise

回答

2

我們c的編碼的源編碼和輸出編碼通過使運行時參數以命令如下:

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

或通過加入線在pom.xml

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

通過命令行'project.build.sourceEncoding'設置編碼已經通過pom文件中的屬性區域通過屬性完成..無需在命令行上再次執行該操作。最重要的是設置文件編碼... – khmarbaise

0

你可以嘗試將其指定爲命令行參數,例如:

java -Dfile-encoding=UTF-8 -jar yourfile.jar 
相關問題