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?
I had the same problem today. Setting project.build.sourceEncoding
to UTF-8 will not work. All the filtered files will be copied in ISO-8859-1
(actually I didn't test but I am sure they are not copied in UTF-8
).
My solution is declaring two <resource>
sections. One to include all the files you really need to filter. The other one to copy other resources with <filtering>
set to false.
It works for me because I don't need to filter I18N files and the file which needs to be set value when build contains only ASCII characters.
Not really an answer to your question (sorry), but I think it is useful information about the property project.build.sourceEncoding
This property is an attempt to simplify the encoding management in maven projects.
The idea is that all plugins use it as default encoding value whenever the encoding is not specified in the plugin configuration it self.
Using or not this property as default encoding value is only a recommendation for plugin developers.
I think this is done in all major and recent plugins, but one important exception is the maven-war-plugin before version 2.2
sources :
- discussion about
project.build.sourceEncoding
is here.
- war-plugin encoding details is here.
In Windows>Preferences>General>Workspace there is a radio button for "Text file encoding". I had UTF-8 set and it was breaking all my special characters in the code.
as Default in Windows it´s "Cp1252" I think.