Encoding troubles UTF-8 in Eclipse/Rational Application Developer...

Uh, I never understood at all what is the reason for all these encoding types!
I had to do some modifications on a custom made JavaEE project which uses velocity template engine. I ended up having a lots of encoding problems.

Now I want to write sort of a step by step instruction how fix it.

Ok, so let's start.
Sooo, you have troubles with your spring/javaEE eclipse project. Several steps to take a look:


1) Check here: Window->Preferences->General->Workspace->Text file encoding - set to UTF-8
This setting will let even your new files to be encoded in UTF-8. It is usual cause of troubleshttp://www.blogger.com/img/blank.gif

2) under Window->Preferences search for encoding keyword and set everything you see to UTF-8 (this does not help too much, but sometimes is useful)

3) If your files are created outside eclipse project, check whether they are written/saved in UTF-8 coding. Notepad++ has a nice feature that is able to show you encoding of your file/text and also to convert from one encoding to another. TRY NOT USING UTF-8 WITH BOM (adds additional bytes to the beginning of the textual file so the editors can know this is UTF-8. Otherwise it causes  at the beginning of the file as soon as you get some encoding issues (like with ISO-8859-1 and CP1252)).

3.1) if you find this a bit problematic you can either use:
- Solution with Batch Convert to UTF-8 with Iconv and Sponge (under the moreutils package).
- Use the UTFcast Express Edition

4) Usually, Spring and velocity are nicely interconnected, and easily solve the issue with encodings, but if the velocity is directly used, one has to take care additionally to use the getTemplate function in the following way:
getTemplate(templateFile,"UTF-8");
Otherwise, it defaults to ISO-8859-1.

Comments

Popular posts from this blog

Timeline on Latex

Exporting Skype Chat/Skype Contacts to csv file using the shell script and sqlite3 (usually already installed on mac)

trim() not supported by IE7 and IE8