gpt4 book ai didi

java - 如何更好地将 JVM 编码属性设置为 UTF-8

转载 作者:行者123 更新时间:2023-12-04 03:09:31 24 4
gpt4 key购买 nike

当我尝试使用 Maven 打包项目时,我收到了这个

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

应用程序属性

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。

最佳答案

我们可以通过将运行时参数传递给命令来对源编码和输出编码进行编码,如下所示:

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>

关于java - 如何更好地将 JVM 编码属性设置为 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46379215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com