After some discussions in nbusers mailing list, good discussion has been started in Issue 42638 for file encoding support in NetBeans IDE.
  • 42638 : I18N - Provide support for File Encoding
Current NetBeans does not have enough support of file encoding setting. It's not possible to control the encoding of plain text files such as JavaScript file, it always will be stored as platform encoding. For example, when you use NetBeans IDE in Japanese eucJP locale, all text files will be stored in eucJP. We often use JavaScript files in web application and we want to use UTF-8 in them, but there is no way to change such settings now.


See the screenshot above, encoding of only Java source file can be controlled in current NetBeans on option dialog. The setting can be changed in entire IDE and per individual file, but it's not realistic. We usually don't use different encoding in individual file in one project. So I think the setting should be stored as project property. It also can help when we use version control system e.g. CVS. After checking out NetBeans projects from CVS, we will be able to get file encoding from project property.

Did you have any trouble about file encoding when you use NetBeans? If so, please join the discussion of Issue 42638.
Comments:

There is a workaround, to set the encoding for the entire JVM: -Dfile.encoding=UTF-8 Its not perfect, but can help.

Posted by Claudio Miranda on August 25, 2006 at 12:17 AM JST #

Thanks Claudio for comment. Yes, I know and many folks replied that workaround whenever the same question was posted to the mailing list. We missed the fix in NetBeans 5.0, 5.5 will be a just update release for Java EE 5. I hope it will be fixed in 6.0.

Posted by Masaki on August 25, 2006 at 06:37 PM JST #

-Dfile.encoding=UTF-8 it's buggy, when I use it, its encoding problem with templates and templates params as I reported in Issue 73038

Posted by Tomas Prochazka on September 11, 2006 at 10:58 PM JST #

Thank you Tomas for the comment. Yes, the bug is exactly what we want to fix. Actually there is no way to set encoding to UTF-8 on Windows. Could you vote to Issue 42638? Good news is that the status of Issue 42638 has been changed to "started". I hope it will be fixed in Trunk.

Posted by Masaki on September 11, 2006 at 11:09 PM JST #

I had a problem with Russian bundle files in v4.1 on Windows. Files created in Notepad and saved as Unicode. When opened in IDE - editor shows garbage. An HTML file with <META encoding=UTF-8> shows perfectly. From what I've read here - obviously there's no way working with these files in IDE - even in v5. Question: will IDE corrupt such files in the WAR on build?

Posted by Gene Kouras on November 01, 2006 at 11:11 AM JST #

Thank you Gene for comment. In my understanding, the contents of these files will not be corrupted until you open and store it on Editor. Editor can not handle the encoding such text files..

Posted by Masaki on November 01, 2006 at 05:48 PM JST #

I have an idea: add "Reload As Different Encoding" and "Save As Different Encoding" when process text files. This can give the developers the power of manually choosing encoding of text files.

Posted by LiuYan on November 22, 2006 at 04:03 PM JST #

Another idea: make a project configuration setting - "files encoding" and use this encoding in opening and saving files in current project

Posted by vigor on January 09, 2007 at 08:01 PM 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:23 PM JST #

i am running mac osx in japanese. should netbeans pick this up as default encoding for the system?

it has problems reading simple UTF-8 template files, coming out as mojibake (with or without BOM).

is there any workaround for this? i dont mind if all files are treated as utf8.

this is a shame, as this was the main reason to switch away from textmate - finally to be able to enter japanese text.

残念ですね。

Posted by dc on September 25, 2007 at 12:59 AM JST #

Thank you very much for comment, dc. Do you use .java files? or some other files? Have you tried NetBeans 6.0? It's can handle UTF-8 encoding by default. You can customize the encoding on Project Properties.

Posted by masaki on September 25, 2007 at 12:02 PM JST #

I've recently got similar problem.

I'm trying to use russian language in .properties file in Netbeans 5.5.1 under Ubuntu Linux. UTF-8 is the default encoding, but still I've got garbage instead of my messages.

However, HTML files with russian language edited in NetBeans look okay.

I've tried to edit and save that .properties file with Gedit, and the behavior is a little bit different. Now instead of just question marks (?????) which I saw when the .properties file was edited in NetBeans, I've got complete garbage (Инд) where it supposed to be "Индекс".

Posted by sp on September 25, 2007 at 07:07 PM JST #

Hi sp, thanks for comments. Hmm, I understand that NetBeans opens .properties files as unicode ascii, not the native encoding. So when you open the .properties files, it should be like \u...\u... instead of native characters. NetBeans does not use native characters in Editor. How about using "Open" action to edit the .properties files? It should be OK, properties editor will be invoked. See the screeshot in http://blogs.sun.com/katakai/resource/nb_rb_2.jpg. You can see the native characters on that Editor.

Posted by masaki on September 25, 2007 at 07:38 PM JST #

Btw, please note this encoding setting is just for .java file, not for .properties file. This behavior is the same even on NetBeans 6.0. .properties files are always being stored as unicode ascii.

Posted by masaki on September 25, 2007 at 07:42 PM JST #

masaki, thanks a lot, that did it.
I've opened the file with the context menu's "open", entered russian values and it displays okay :).

Posted by sp on September 25, 2007 at 07:52 PM JST #

It's great!
There is one enhancement at 6.0. When you use NetBeans 6.0, even "Edit" menu can open the contents of .properties properly, not unicode ascii. So you can edit .properties file directly. But please note that once it's saved, .properties file is stored as unicode ascii.

Posted by masaki on September 25, 2007 at 08:07 PM JST #

I am trying problems with Russian character (cyrillic) also. I am able to copy and paste into the properties file just fine. But when I save it and open it again, all I see are ???? where the cyrillic character were. Do you know how I can save a properties with the cyrillic and have java bring them back up when I specify the appropriate user.language and user.country?
Thanks,
Scott

Posted by scott on September 29, 2007 at 12:20 AM JST #

2 scott:

You have to edit the .properties file in the "properties editor" like on the screenshot, not as a plain text file.
To open the editor you have to right-click on the .properties file in the "Projects" and select "open" in the context menu.

Posted by sp on September 29, 2007 at 12:26 AM JST #

sp THANK YOU SOOOOOOOOOOO MUCH!!!!!!!!!
Scott

Posted by scott on September 29, 2007 at 12:32 AM JST #

Hi! I want to develop existed project in NetBeans. All files are utf-8 encoded in it. I've set project encoding in project properties and now I can see *.java files well, but in *.js files russian text looks like "Подождите". As I understand NetBeans uses my default encoding (win-1251) to show *.js files in editor. How to avoid this behaviour?
Product Version: NetBeans IDE 6.1 (Build 200805300101)
Java: 1.5.0_14; Java HotSpot(TM) Client VM 1.5.0_14-b03
System: Windows XP version 5.1 running on x86; Cp1251; ru_RU (nb)

Posted by dealer on July 11, 2008 at 10:05 PM JST #

Hi Dealer, Thanks for comment. Some of files seem to use the default encoding of your system. To avoid it, could you try to use "-J-Dfile.encoding=UTF-8" option to NetBeans. Please see the reference : http://wiki.netbeans.org/FaqI18nFileEnc

Posted by Masaki on July 11, 2008 at 10:30 PM JST #

Thanks, Masaki! It seems that -J-Dfile.encoding=UTF-8 works for me )

Posted by dealer on July 14, 2008 at 03:18 PM JST #

Post a Comment:
Comments are closed for this entry.

This blog copyright 2009 by katakai