Tip: Encoding Issues with Plug-ins

January 9, 2009 | 1 min Read

Have you ever come across an issue while developing an Eclipse-based application, go to export it and get an evil “Invalid character constant” message or something similar in your logs? This happens when you’re developing an application that requires Unicode characters but your system file encoding is something other than you expect (i.e., on Macs it’s usually MacRoman and on Windows it’s Cp1252). When you go to export, PDE Build will use the default file encoding (see the file.encoding system property) available to the VM. This can cause problems if you’re using Unicode characters in code and on export, PDE Build chooses a default encoding like Cp1252.

In Eclipse 3.5M5, PDE added some checks to make sure that your project encoding matches what would be exported:

This is accomplished via the javacDefaultEncoding.<library> property (in your build.properties file). This doesn’t help you much if you need to do file-specific encodings, but PDE Build supports that via the javacCustomEncodings property. For example: javacCustomEncodings.. = src/org/foo[US-ASCII],\ src/org/foo/bar.java[ISO-8859-1]

Hope this helps!