Wednesday, September 29, 2010

Maven: unmappable character for encoding UTF8

If maven keeps complaining about "unmappable character for encoding UTF8" you are most probably having some special characters within your source code like ä or á. Since your editor is not using UTF-8 as file encoding - like eclipse does not in default settings under windows (it uses platform-specific encoding Cp1252) - this will cause problems with the maven-compiler-plugin.

For quick-fixing this problem you might want to add the following to your pom.xml:

Set the encoding to whatever your source files are using. Anyway I would recommend to remove all the characters causing those problems and also change the default encoding to UTF-8 to be consistent with the maven defaults and not having to set this explicitly.

Generally not using special characters in source code should prevent those problems completely that might occur quickly again introduced by developers who for any reason do not use UTF-8 as default encoding again and the trouble will start anew.

Friday, September 24, 2010

Escaping Strings using org.apache.commons.lang.StringEscapeUtils

You often run into the problem of escaping Strings from certain characters that need to be encoded as entitys in the format you use.

Apache has a great library in its commons-lang repository willing to do all that nasty and time-consuming work for you. Simply add this dependency to your pom.xml and start using it:

The class to go for when wanting to escape Strings is StringEscapeUtils.

Escaping html strings is as easy as

Have fun!