首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring 10系统属性“file.encoding”

Spring 10系统属性“file.encoding”
EN

Stack Overflow用户
提问于 2017-08-01 05:09:51
回答 2查看 4.2K关注 0票数 0

我试图用以下命令启动:

代码语言:javascript
复制
java -jar api-0.0.1.jar -Dfile.encoding=UTF-8

但是,如果出现以下错误,则会失败:

代码语言:javascript
复制
07:52:54.573 [main] INFO com.example.domain.api.Application - Starting application...
2017-08-01 07:52:55.071 ERROR 5792 --- [           main] o.s.b.c.FileEncodingApplicationListener  : System property 'file.encoding' is currently '
Cp1251'. It should be 'UTF-8' (as defined in 'spring.mandatoryFileEncoding').
2017-08-01 07:52:55.074 ERROR 5792 --- [           main] o.s.b.c.FileEncodingApplicationListener  : Environment variable LANG is 'null'. You could
 use a locale setting that matches encoding='UTF-8'.
2017-08-01 07:52:55.075 ERROR 5792 --- [           main] o.s.b.c.FileEncodingApplicationListener  : Environment variable LC_ALL is 'null'. You cou
ld use a locale setting that matches encoding='UTF-8'.
2017-08-01 07:52:55.082 ERROR 5792 --- [           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).
        at org.springframework.boot.context.FileEncodingApplicationListener.onApplicationEvent(FileEncodingApplicationListener.java:74) ~[spring-b
oot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.context.FileEncodingApplicationListener.onApplicationEvent(FileEncodingApplicationListener.java:46) ~[spring-b
oot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring
-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring
-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) ~[spring
-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) ~[spring-boot
-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) ~[spring-boot-1.5.6.R
ELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEAS
E]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:296) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at com.example.domain.api.Application.main(Application.java:36) [classes!/:0.0.1]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [api-0.0.1.jar:0.0.1]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [api-0.0.1.jar:0.0.1]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [api-0.0.1.jar:0.0.1]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [api-0.0.1.jar:0.0.1]

而且,我的Maven pom.xml中有以下属性:

代码语言:javascript
复制
<properties>
    <java.source.version>1.8</java.source.version>
    <java.target.version>1.8</java.target.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <file.encoding>UTF-8</file.encoding>
</properties>

我做错了什么,如何正确启动这个应用程序?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-01 05:43:38

Java 6支持两个编码集,新的java.nio API使用的规范名称在许多情况下与java.io和java.lang API中使用的名称不同。

  • 如果您对java.nio API使用规范名称,则需要使用: UTF-8。
  • 如果您对java.io和java.lang API使用规范名称,则需要使用: UTF8

所以使用-Dfile.encoding=UTF-8-Dfile.encoding=UTF8

票数 3
EN

Stack Overflow用户

发布于 2020-10-29 15:16:54

系统属性'file.encoding‘目前是’is 1252‘。它应该是'UTF-8‘(在’spring.mandatoryFileEncoding‘中定义)。

在Windows 10上使用Netbeans 12.0可以通过如下修改nbactions.xml来修复错误:

原版:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <!-- ... -->
    <action>
        <properties>
            <exec.args>-classpath %classpath br.com.example.Application</exec.args>
            <exec.executable>java</exec.executable>
        </properties>
    </action>
    <!-- ... -->
</actions>

-Dfile.encoding=UTF-8 exec.args**:**的第一名中添加了

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <!-- ... -->
    <action>
        <properties>
            <exec.args>-Dfile.encoding=UTF-8 -classpath %classpath br.com.example.Application</exec.args>
            <exec.executable>java</exec.executable>
        </properties>
    </action>
    <!-- ... -->
</actions>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45429372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档