I am developing a maven based web project. In my web module I am using different language specific resource bundles (german, spain, ....). All my sources are based on UTF-8 and erverything works fine. Now it was necessary to acitvate maven resouce filtering to replace some configurations depending on different maven profiles.
my pom.xml:
.....
<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">
.....
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
....
From this moment my war file contains resource bundles with wrong encoding. For example German umlauts are no longer displayed in my web application correctly. When I disable the resource filtering everything is well again.
The only solution I found was to set the property project.build.sourceEncoding to 'ISO-8859-1'
<properties>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
But I can not understand why this is necessary? All my sources are UTF-8 and also my application is based on UTF-8? What will happen if I need to add a resource bundle with - for example Japanese characters?
I am developing on linux using Eclipse 4.2 and Maven 3
You can specify the encoding in the resources plugin configuration like so:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
...
<encoding>UTF-8</encoding>
...
</configuration>
</plugin>
</plugins>
...
</build>
...
</project>
Link to the Docs
Are you sure your resource bundles (.properties) are using UTF-8
?
java.util.Properties
assumes ISO-8859-1
for resource bundles encoding, see http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader), and I think Eclipse (as well as IntelliJ IDEA) honors this default encoding for these files (.properties).
So go and check with a text editor the current encoding for these files in your project source tree, in Windows Notepad 2 can help you with this.
And then configure maven-resources-plugin
like indicated here Configure encoding for different filetypes in maven?
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