Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot WIndows 10系统属性';文件编码';_Java_Maven_Spring Boot_Utf 8_Windows 10 - Fatal编程技术网

Java Spring Boot WIndows 10系统属性';文件编码';

Java Spring Boot WIndows 10系统属性';文件编码';,java,maven,spring-boot,utf-8,windows-10,Java,Maven,Spring Boot,Utf 8,Windows 10,我尝试使用以下命令启动Spring Boot uber jar: java -jar api-0.0.1.jar -Dfile.encoding=UTF-8 但它失败了,出现以下错误: 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.FileE

我尝试使用以下命令启动Spring Boot uber jar:

java -jar api-0.0.1.jar -Dfile.encoding=UTF-8
但它失败了,出现以下错误:

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中有以下属性:

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

1.8
1.8
UTF-8
UTF-8

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

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

  • 如果要为java.nioapi使用规范名称,则需要使用:UTF-8
  • 如果要为java.io和java.langAPI使用规范名称,则需要使用:UTF8

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

  • 如果要为java.nioapi使用规范名称,则需要使用:UTF-8
  • 如果要为java.io和java.langAPI使用规范名称,则需要使用:UTF8
因此,请使用系统属性“file.encoding”当前为“Cp1252”。它应该是“UTF-8”(如“spring.mandatoryFileEncoding”中所定义)

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

原件:

<?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>
<?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>
系统属性“file.encoding”当前为“Cp1252”。它应该是“UTF-8”(如“spring.mandatoryFileEncoding”中所定义)

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

原件:

<?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>
<?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>

我尝试了所有这些变体:
java-jar-api-0.0.1.jar
java-jar-api-0.0.1.jar-Dfile.encoding=UTF-8
java-jar-api-0.0.1.jar-Dfile.encoding=UTF8
不幸的是,我没有找到原因——应用程序参数的顺序很重要,现在它可以工作了:
java-Dfile.encoding=UTF-8-jar api-0.0.1.war
mvn-spring-boot:run-Dspring-boot.run.jvmArguments=“-Dfile.encoding=UTF-8”可以工作。但是我想在一个配置文件中配置它,我尝试了所有这些变体:
java-jar-api-0.0.1.jar
java-jar-api-0.0.1.jar-Dfile.encoding=UTF-8
java-jar-api-0.0.1.jar-Dfile.encoding=UTF8
不幸的是,没有人能找到原因——应用程序参数的顺序很重要,现在它可以工作了:
java-Dfile.encoding=UTF-8-jar api-0.0.1.war
mvn-spring-boot:run-Dspring-boot.run.jvmArguments=“-Dfile.encoding=UTF-8”可以工作。但我想在配置文件中配置它提示:更改后,您需要清理并重建解决方案。提示:更改后,您需要清理并重建解决方案。