Skip to content

Character encoding issues

Phil Callender edited this page Jul 15, 2013 · 4 revisions

The Eclipse Workbench is generally quite tolerant of character encoding, but the standard Java compiler, as used by Maven and the ToolTwist Controller, is not quite tolerant. If a file is in an inappropriate character format, non-ASCII characters often result in a compiler error. For example:

    [javac] /ControllerV8/launchpads/myrp-dev/image/extension-projects/myrp_t/src/com/myrp/util/MathUtil.java:67: error: unmappable character for encoding UTF-8
    [javac] 		lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;  // normalise to -180..+180�
    [javac] 		                                                                                  ^
    [javac] /ControllerV8/launchpads/myrp-dev/image/extension-projects/myrp_t/src/com/myrp/util/PaymentGatewayUtil.java:42: error: unmappable character for encoding UTF-8
    [javac] 	public static final String ERROR_EMAIL_SUBJECT = "MYRP Website cannot connect to Merchant Gateway � Severity 1";
    [javac] 	                                                                                                  ^

The solution to all these problems is to convert these files to UTF-8 format. One advantage of UTF-8 is that ASCII is a subset of UTF-8. In other words, a regular test file containing ASCII text, is already in UTF-8 format by default.

Determining the file format

On OSX and Linux systems, the encoding of a file can be determined using the file command:

file MathUtil.java
MathUtil.java: ISO-8859 Java program text

Converting on the command line

iconv -f iso-8859-1 -t utf-8 MathUtil.java > ,new
mv ,new MathUtil.java

Converting within Eclipse

  1. Open the file in Eclipse and copy the entire file into the cut&paste buffer ( Ctrl-A, Ctrl-C ).
  2. Right click on the file in the Project Explorer and select Properties.
  3. In the Resource section, under Text File Encoding, select Other and UTF-8 and press OK.
  4. Replace the source code from the cut&paste buffer and save the file ( Ctrl-A, Ctrl-V, Ctrl-S ).

Note that simply changing the encoding will result in the non-ASCII characters being converted incorrectly.

--

Clone this wiki locally