I have this pom:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.1sttech</groupId> <artifactId>SpringREST</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>SpringREST</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

I launch in Intelli IDE everything works. I launch in NetBeans I get errors:

 --- exec-maven-plugin:1.2.1:exec (default-cli) @ SpringREST --- 2016-10-26 17:32:01.303 ERROR 12248 --- [ restartedMain] osbcFileEncodingApplicationListener : System property 'file.encoding' is currently 'Cp1251'. It should be 'utf-8' (as defined in 'spring.mandatoryFileEncoding'). 2016-10-26 17:32:01.307 ERROR 12248 --- [ restartedMain] osbcFileEncodingApplicationListener : Environment variable LANG is 'null'. You could use a locale setting that matches encoding='utf-8'. 2016-10-26 17:32:01.307 ERROR 12248 --- [ restartedMain] osbcFileEncodingApplicationListener : Environment variable LC_ALL is 'null'. You could use a locale setting that matches encoding='utf-8'. 2016-10-26 17:32:01.307 WARN 12248 --- [ restartedMain] osboot.SpringApplication : Error handling failed (no error message) 2016-10-26 17:32:01.312 ERROR 12248 --- [ restartedMain] osboot.SpringApplication : Application startup failed java.lang.IllegalStateException: The Java Virtual Machine has not been configured to use the desired default character encoding (utf-8). ... Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project SpringREST: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project SpringREST: Command execution failed. 

I launch from the console mvn spring-boot: run I get errors:

 [INFO] --- spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) @ SpringREST --- [INFO] Attaching agents: [] 2016-10-26 17:16:22.213 ERROR 13208 --- [ restartedMain] osbcFileEncodingApplicationListener : System property 'file.encoding' is currently 'Cp1251'. It should be 'utf-8' (as defined in 'spring.mandatoryFileEncoding'). 2016-10-26 17:16:22.218 ERROR 13208 --- [ restartedMain] osbcFileEncodingApplicationListener : Environment variable LANG is 'null'. You could use a locale setting that matches encoding='utf-8'. 2016-10-26 17:16:22.221 ERROR 13208 --- [ restartedMain] osbcFileEncodingApplicationListener : Environment variable LC_ALL is 'null'. You could use a locale setting that matches encoding='utf-8'. 2016-10-26 17:16:22.221 WARN 13208 --- [ restartedMain] osboot.SpringApplication : Error handling failed (no error message) 2016-10-26 17:16:22.226 ERROR 13208 --- [ restartedMain] osboot.SpringApplication : Application startup failed java.lang.IllegalStateException: The Java Virtual Machine has not been configured to use the desired default character encoding (utf-8). [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project SpringREST: Could not exec java: Application finished with exit code: 1 -> [Help 1] 

I understand the problem in the encoding and how to fix it? System property 'file.encoding' is currently 'Cp1251'. And most importantly, why does Intelli IDE work?

  • Not sure, but maybe IDEA runs with -Dfile.encoding=utf8 ? - Slava Semushin
  • So what to do to run from different IDEs and from the console, respectively? - Sergei R
  • @SergeiR, Add this flag, no? - post_zeew
  • @post_zeew Where to? I do not know where to add it - Sergei R
  • one
    with argument -Dfile.encoding = utf8 the same errors. - Sergei R

1 answer 1

When run through mvn, spring-boot: run caught the same error. It was decided to remove the spring.mandatory-file-encoding=UTF-8 line from the application.properties file.