Since I updated my Windows 10 and installed new OpenJDK 11.0.4 my Spring integration tests are not running anymore in the Maven context. Starting it within Eclipse is fine and still working but running it with mvn clean install it is not working aynmore with the error:
18:01:01.340 ERROR [main]:[org.springframework.boot.context.FileEncodingApplicationListener] System property 'file.encoding' is currently 'Cp1252'. It should be 'UTF-8' (as defined in 'spring.mandatoryFileEncoding').
18:01:01.341 ERROR [main]:[org.springframework.boot.context.FileEncodingApplicationListener] Environment variable LANG is 'null'. You could use a locale setting that matches encoding='UTF-8'.
18:01:01.341 ERROR [main]:[org.springframework.boot.context.FileEncodingApplicationListener] Environment variable LC_ALL is 'null'. You could use a locale setting that matches encoding='UTF-8'.
18:01:01.344 ERROR [main]:[org.springframework.boot.SpringApplication] Application run 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:76)
at org.springframework.boot.context.FileEncodingApplicationListener.onApplicationEvent(FileEncodingApplicationListener.java:47)
I have set UTF-8 encoding everywhere I was able to set.
- In the application-test.properties
file.encoding=UTF-8 spring.mandatoryFileEncoding=UTF-8 spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true
- in the maven properties and plugin configurations:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>Java 11</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<java.version>11</java.version>
</properties>
<build>
<finalName>${project.artifactId}-${build-version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${java.version}</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version><!--$NO-MVN-MAN-VER$ --> <!-- TODO move to stable version when available -->
</dependency>
</dependencies>
</profile>
- In the integration tests properties:
@RunWith(SpringRunner.class)
@SpringBootTest(properties = "file.encoding=UTF-8", classes = SEBServer.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
- While starting maven as a VM argument
mvn clean install -Dfile.encoding=UTF-8
can anyone tell me where else I can set the encoding? there seems to be as many possible places as stars in the sky but nowhere the right one.
Thanks!
maven-surefire-plugin
(though I thought this was for unit tests not integration test). This post: github.com/intuit/karate#test-reports suggests that you should include asystemProperties
child in your configuration. This would have a<file.encoding>
child with contentUTF-8
(I think). If the issue is you should be using a plugin for integration tests, thenmaven-failsafe-plugin
, checkout maven.apache.org/surefire/maven-failsafe-plugin/examples/…systemProperties
are deprecated for themaven-surefire-plugin
and you should usesystemPropertyVariables
for that too.