Filed under: Java, Maven, — Tags: Cp1252, MacRoman, National characters, UTF-8 — Thomas Sundberg — 2011-02-17
We had a problem in my current Java project. Whenever somebody wrote a comment using Swedish national characters, åäö or ÅÄÖ, and later tried to build the system with Maven we got the error:
unmappable character for encoding UTF-8
We had set our Maven build to use UTF-8 and hoped that should be enough. It turns out that when using Intellij IDEA as IDE you need to change a setting on which character encoding that should be used when saving a file. The default setting is <System Default>. This is probably a good design choice from Jetbrains, but in our case it isn't the best option.
To change this, go to Settings and File Encodings and set the property IDE Encoding to UTF-8. While you are there, take a look at the setting Autodetect UTF-encoded files and make sure that it is set.
This is of course obvious since Windows users normally don't use UTF-8 by default, default is Cp1252, and in my case the default setting on my Mac is MacRoman. But never the less, it has to be set properly for every developer in the project.
All files has to be edited before the change will propagate to all files, but this is an active project so it will happen soon. Similar to fixing bad code into Clean Code, fix one thing at a time. It will eventually get better and finally god.