[RSS]
CategoryNeedCleanup There is more up-to-date information in FaqI18nProjectEncoding.

How can I use UTF-8 encoding in Java source files and JavaScript files in my project? (for NetBeans 5.X and earlier)

NOTE - the information below applies to NetBeans 5.X and earlier releases; for NetBeans 6.0, there is now a project encoding property and addtional functionality for file encoding handling; a separate faq item will be written for this; also see NetBeans 6.0 on line help.

NetBeans IDE uses OS platform encoding by default as the encoding of plain text file (e.g. Java source, JavaScript and other files). These files can not contain any encoding information, so the IDE uses the default encoding of the operating system for them. For example, when you use the Japanese localization of Windows, the encoding of Java files will be Shift_JIS by default.

JSP, HTML and XML files can contain encoding information defined by a tag. You can put such information into the files, e.g. as a meta tag in HTML files.

There is no perfect solution for NetBeans 5.x right now. The configurations below are known solutions.

How to set the encoding on UNIX/Linux?

If you use the UNIX/Linux platform, you can start the IDE with the UTF-8 locale. Most modern UNIX/Linux platforms support UTF-8 locales. For example, if you use Japanese,

% export LANG=ja_JP.UTF-8
% netbeans

How to set the encoding on Windows?

There is no way in Windows to change the locale at IDE startup. This means for example, that the IDE always uses Shift_JIS on Japanese Windows. When you want to use UTF-8 encoding in Java sources file, you need to change the encoding of the source editor, and add a compiler option. Please follow the steps below.

  1. Open Option dialog by Tools > Option
  2. Switch to Advanced Options
  3. Click the Java Source node of the Editor Editing category
  4. Find the "Default Encoding" field and enter "UTF-8" into the field

This is the setting just for the Editor. Now you need to set compiler options:

  1. Open the project's Property dialog
  2. Find the "Aditional Compiler Option" field in the "Build" category
  3. Enter "-encoding utf-8" into the field

How to change the encoding for other text files, e.g. .txt, .js files?

Currently, there is no recommended solution. Some people use the "-J-Dfile.encoding=UTF-8" switch as IDE startup option, but it's not a perfect solution.


Applies to: NetBeans 5.0, 5.5

Platforms: All