Specifying UTF-8 Encoding

You can specify character encoding for objects in Eclipse.

Overview

You can specify character encoding for the following objects in Eclipse:

Files You can specify the character encoding for individual files or for all files of a given content type.
Projects Specifying character encoding for a project sets the default for all new files created in that project. You can set character encoding for projects individually, or for all projects created in an Eclipse workspace.
Workspaces Specifying character encoding for a workspace sets the default for all new projects created in that workspace.

The following sections summarize the procedures you can use to specify UTF-8 character encoding in Eclipse. Refer to your Eclipse user documentation for additional information.

Setting encoding for a file

To set the character encoding for an individual file:
  1. In the Package Explorer, right-click the file whose encoding you want to set and the choose Properties from the shortcut menu.
  2. On the Resource page, in the Text file encoding group, select Other and then choose UTF-8 from the list.
  3. Click OK to save the settings and close the Properties dialog box.

Tip: You can also set the character encoding based on a file’s content type. See Other Preferences for Specifying Character Encoding for more information.

Setting encoding for a project

Setting the character encoding for a project sets the encoding for any new files created in that project.

To set the character encoding for a project:

  1. In the Package Explorer, right-click the project whose encoding you want to set and then choose Properties from the shortcut menu.
  2. On the Resource page, in the Text file encoding group, select Other and then choose UTF-8 from the list.
  3. Click OK to save the settings and close the Properties dialog box.

Setting encoding for a workspace

Setting character encoding for a workspace sets the default for all new projects created in that workspace.

To set character encoding for a workspace:

  1. From the main menu, select Window > Preferences.
    The Preferences dialog box appears.
  2. Navigate General > Workspace to display the Workspace page.
  3. In the Text file encoding group, select Other and then choose UTF-8 from the list.
  4. Click OK to save the settings and close the Properties dialog box.

Other preferences for character encoding

In addition to using Eclipse preferences to set character encoding for workspaces, you can also use preferences to set character encoding based on content types, and for files associated with other Eclipse plug-ins you have installed (plug-ins for Web and XML application development, for example).

To locate all the places where you can specify preferences for character encoding, type “encoding” in the Preference dialog box Filter field. As you type, titles of the preference pages containing “encoding” are displayed in the Preferences dialog box left pane:

Navigate the preference pages for the plug-ins you have installed and review, and optionally set character encoding on those pages.

For example, to set character encoding based on a file’s content type:

  1. From the main menu, select Window > Preferences. The Preferences dialog box opens.
  2. Navigate General > Content TypesGeneral to display the Content Types page.
  3. Scroll through the Content types field, review the corresponding file associations, and set the value in the Default encoding field as needed.
  4. Click the OK button to save the settings and close the Preferences dialog box.