Wednesday, March 31, 2010

Loading Java properties in UTF-8

One of the latest stupid problems I've encountered: Java *.properties files are always loaded in ISO-8859-1 encoding and there is no way to change that. But in our project we wanted to have them in UTF-8 so that non-Latin files could be human readable. We use JSTL "fmt" tag library which loads messages from *.properties files (and guess in which encoding).

The simple solution I've come up is build-time native2ascii conversion. This can be done using the native2ascii-maven-plugin. This example shows what to add to pom.xml (assuming that your *.properties files are in src/main/resources/l10n):

             <!-- exclude resources handled by native2ascii-maven-plugin (otherwise they will be overwritten again) -->


No comments: