1

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.

  1. In the application-test.properties
file.encoding=UTF-8
spring.mandatoryFileEncoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
  1. 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>
  1. In the integration tests properties:
    @RunWith(SpringRunner.class)
    @SpringBootTest(properties = "file.encoding=UTF-8", classes = SEBServer.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
  1. 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!

11
  • Is there anywhere that you are setting the encoding property to Cp1252? Commented Dec 15, 2020 at 17:38
  • @BillNaylor No. It is also the case that the maven build works on other machines and CI integration systems but not locally on Windows 10 with Open JDK 11.0.4
    – Andreas
    Commented Dec 15, 2020 at 18:03
  • This may be a clue, I found this page: en.wikipedia.org/wiki/…. which is saying that that encoding is used by default in legacy Windows Components (?). So maybe there is some way to stop the default? Commented Dec 15, 2020 at 18:43
  • 1
    I've looked into this issue a bit, you mention you are using the 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 a systemProperties child in your configuration. This would have a <file.encoding> child with content UTF-8 (I think). If the issue is you should be using a plugin for integration tests, then maven-failsafe-plugin, checkout maven.apache.org/surefire/maven-failsafe-plugin/examples/… Commented Dec 17, 2020 at 16:52
  • 1
    Actually maven.apache.org/surefire/maven-surefire-plugin/examples/… suggests that systemProperties are deprecated for the maven-surefire-plugin and you should use systemPropertyVariables for that too. Commented Dec 17, 2020 at 16:56

3 Answers 3

2

It seems that the encoding Cp1252 is used by default in some legacy Windows Components (see: https://en.wikipedia.org/wiki/Windows-1252#:~:text=Windows%2D1252%20or%20CP%2D1252,character%20encoding%20in%20the%20world)
As the OP mentions that the problem (integration/unit tests not running any more) go's away if the parameter -Dfile.encoding=UTF-8 is added to the mvn invocation, it seems that we need a way to hard code this in the pom.xml.
This may be done by including a systemPropertyVariables child in the configuration element of the unit test plugin maven-surefire-plugin. A similar systemPropertyVariables child exists for the integration test plugin maven-failsafe-plugin.
References: https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html
and
https://maven.apache.org/surefire/maven-failsafe-plugin/examples/system-properties.html

1

This work for me:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
     <argLine>-Dfile.encoding=UTF-8</argLine>
  </configuration>
</plugin>
0

I had the same problem and i solved it by adding this

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-Dfile.encoding=UTF-8</argLine>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <argLine>-Dfile.encoding=UTF-8</argLine>
    </configuration>
</plugin>

Not the answer you're looking for? Browse other questions tagged or ask your own question.