After I upgraded to Java 17 using the Microsoft OpenJDK, all the tests that use non-ASCII characters are failing due to encoding failure issues.
For instance, one of my tests uses the following Unicode characters (e.g., U+2660 to U+2663):
entityManager.persist(
new Suit()
.setName("Club")
.setSymbol("♣")
);
entityManager.persist(
new Suit()
.setName("Diamond")
.setSymbol("♦")
);
entityManager.persist(
new Suit()
.setName("Heart")
.setSymbol("♥")
);
entityManager.persist(
new Suit()
.setName("Spade")
.setSymbol("♠")
);
How to fix it?
While upgrading to the Java 17 version using the OpenJDK built by Microsoft, I also ran into problems because the Java source files were now encoded using the default Windows encoding, instead of UTF-8.
To fix the problem, set the file.encoding
property to UTF-8
.
The easiest way to do it is to set the MAVEN_OPTS
environment variable:
MAVEN_OPTS=-Dfile.encoding=UTF-8
Another option is to pass it to the Maven Surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
And, if you want to start a Java program, then pass the -Dfile.encoding=UTF8
property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With