Java File Encoding

The application I’m developing has to work in Spanish. I have a string literal in my Java code that includes the ó character. I develop in Eclipse and compile using Ant on OS X and had no problems.

When I moved my code out to production and tried to compile / run it on Linux, I started getting problems. The ó was coming out like “^@” or “?” depending on where I was viewing it (browser or terminal). I noticed a compiler warning from iajc (AspectJ compiler) about “unmappable character for encoding UTF8”. I came across this withdrawn bug on Sun’s site, which clued me in. I modified my build.xml script to explicitly use encoding=”UTF-8″. This fixed the compiler warning, but the code was still failing at run time.

Turns out the culprit was that Eclipse uses your platform encoding by default. On OS X, that is MacRoman. After an absolute ton of clicking through options, I finally found how to set the default encoding for all files under Window->Preferences->General->Workspace->Text File Encoding. I changed this to Other->UTF-8, recompiled the world, and voilà! (Pun intended 8) )

I’ll leave you with this closing thought paraphrased from a recent post on the comp.lang.c++.moderated newsgroup: Why is it still called internationalization if it only has to work in Spanish??

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: