Natthawut Kulnirundorn posted an excellent tip in his blog for how to use UTF-8 encoding in Java source file and its compiling on NetBeans IDE. He is using NetBeans 5.5 on Windows Vista (RC) and Thai languages. On NetBeans 5.x, we have to do the following step when we need to use UTF-8,

 (1) Set encoding for Java file to UTF-8
 (2) Set compile option to use UTF-8

(2) can be changed on project properties dialog, but (1) needs to be changed for each file, not project based. Alternatively, you can change this option (1) in entire IDE setting. It's not easy... Also it will work just for Java source file. It's not possible to control in other plain text files e.g. .js, .txt, .css. The fundamental issue is that these encoding settings are not part of project properties. I had posted about this before,
I hope this issue will be fixed in NetBeans 6.0 as bug 42638. It has been marked as STARTED and target milestone is now 6.0M7.
  • 42638 : I18N - Provide support for File Encoding
Comments:

In fact, You can control encoding of css files. Just add the following @charset "iso-8859-1"; as first line of the css file. I introduced an issue therefore long time ago, and normally it's solved. (except for the diff, encoding seems ignored)

Posted by Vincent Brabant on January 27, 2007 at 01:52 AM JST #

Thank you Vincent!! I didn't know that of css.

Posted by Masaki on January 27, 2007 at 09:54 AM JST #

In NetBeans 6.0 M6, there's no encoding option in file properties (right click on file name), neither encoding option in Tools -> Options -> Advance Options -> Editiong -> Java Editor. Effectively, I found no way to change the encoding of text files.

Posted by bact' on January 28, 2007 at 08:22 PM JST #

for compile option, I can't find it in NetBeans 6.0 M6 as well. But as we can modify Ant's build.xml, just add "encoding" property to "javac" element. <target name="compile" ...> <javac ... encoding="utf-8" ... /> </target> this should work.

Posted by bact' on January 28, 2007 at 08:30 PM JST #

Hi bact', Thank you for comment. I think these options are now being implemented for M7 and will appear at M7 hopefully.

Posted by Masaki on January 28, 2007 at 08:32 PM JST #

For UTF-8 in NB6 or 5 use: "C:\Program Files\netbeans-XX\bin\netbeans.exe" -J-Dfile.encoding=UTF-8

Posted by CzechBier on February 20, 2007 at 06:11 AM JST #

Thank you CzechBier. I understand -J-Dfile.encoding=UTF-8 is one of the workaround but I understand some folks do not like the workaround because it can not solve entire problem.

Posted by Masaki on February 20, 2007 at 11:58 AM JST #

Post a Comment:
Comments are closed for this entry.

This blog copyright 2008 by katakai