143

How can I add UTF-8 support in eclipse? I want to add for example Russian language but eclipse won't support it. What should I do? Please guide me.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Katty
  • 1,707
  • 3
  • 13
  • 18

12 Answers12

288

Try this

  • 1) Window > Preferences > General > Content Types, set UTF-8 as the default encoding for all content types.

  • 2) Window > Preferences > General > Workspace, set Text file encoding to Other : UTF-8

boop
  • 7,413
  • 13
  • 50
  • 94
Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38
  • 15
    I wrote a blog post about this very topic which illustrates this in great detail (with screenshots etc): [Unicode/UTF-8 in your Eclipse Java projects](http://stijndewitt.wordpress.com/2010/05/05/unicode-utf-8-in-eclipse-java/) – Stijn de Witt Apr 05 '14 at 14:29
  • I am not able to accept UTF-8 characters as input from console. Scanner sc=new Scanner(System.in); sc.nextLine(); here if I give non-English characters it gets something garbage. What changes needed in setting or in program ? – Kaushik Lele Jan 16 '15 at 07:06
  • 2
    Kaushik Lele: Your question does not relate the the question asked here. I invite you to search for your solution in other questions, or if none exist, ask your own question. – meustrus Feb 09 '15 at 17:06
  • That is pretty awful... surely the encoding of a project should be dependent on the project, not on the global Eclipse settings? – Nyerguds Sep 06 '16 at 07:48
  • 2
    @Nyerguds: In the Package Explorer, right-click on a project and choose `Properties'. The first entry `Resource' offers exactly what you want. – Ralph Nov 30 '16 at 13:59
  • Why `Default encoding` of `JS Object Notation File` not works for `*.json`? – softwarevamp Sep 26 '19 at 03:22
46

Open Eclipse and do the following steps:

  1. Window -> Preferences -> Expand General and click Workspace, text file encoding (near bottom) has an encoding chooser.
  2. Select "Other" radio button -> Select UTF-8 from the drop down
  3. Click Apply and OK button OR click simply OK button

enter image description here

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
user3249411
  • 461
  • 4
  • 3
12

You can set a default encoding-set whenever you run eclipse.exe.

  1. Open eclipse.ini in your eclipse home directory Or STS.ini in case of STS(Spring Tool Suite)
  2. put the line below at the end of the file

-Dfile.encoding=UTF-8

tommybee
  • 2,409
  • 1
  • 20
  • 23
8

Just right click the Project -- Properties and select Resource on the left side menu.

You can now change the Text-file encoding to whatever you wish.

Kal
  • 24,724
  • 7
  • 65
  • 65
  • I followed the steps you mentioned above and changed into UTF-8 for console printing for Chinese an Russian languages. But unfortunately it didn't work. – Ripon Al Wasim Feb 13 '18 at 06:19
5

Right click on main source -> Run As -> Run Configurations -> (x)= Arguments -> VM arguments -> add:

-Dsun.stdout.encoding=UTF-8
Toni Zeidler
  • 163
  • 1
  • 11
  • it worked for me , thanks. In fact, until I reach this answer comment, I tried all, but unfortunately they didn't work, maybe it also depends on OS system environment. – Farkhod Abdukodirov Mar 28 '23 at 07:55
2

September 24, 2022 Update:
JDK 19 (released on September 20, 2022) has System property

stdout.encoding

which can be set to UTF-8, i.e. add the following option to the java command:

-Dstdout.encoding=UTF-8
Abra
  • 19,142
  • 7
  • 29
  • 41
0

I tried all settings mentioned in this post to build my project successfully however that didn't work for me. At last I was able to build my project successfully with mvn -DargLine=-Dfile.encoding=UTF-8 clean install command.

JoSSte
  • 2,953
  • 6
  • 34
  • 54
Divu
  • 11
  • 1
0

You can set an explicit Java default character encoding operating system-wide by setting the environment variable JAVA_TOOL_OPTIONS with the value -Dfile.encoding="UTF-8". Next time you start Eclipse, it should adhere to UTF-8 as the default character set.

See https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html

Abdull
  • 26,371
  • 26
  • 130
  • 172
0

If you have problems with JSON files, it turns out in some Eclipse versions there is an embedded JSON Validator. You can turn it off by doing the steps below:

Go to Windows->Validation and Uncheck JSON validation checkboxes

A.Ktns
  • 381
  • 6
  • 12
0

If you have Windows 11, and none of the previous answers worked, you could need to change your Region settings. Follow these steps:

Quick instructions:

Windows search > Control Panel > Region > Administrative tab > Change system locale... > check Beta: Use Unicode UTF-8 for worldwide language support > OK > Restart now

Full instructions:

  1. Go to the Windows search: Press the Win key, or just click on the Search button. Another way you can go is by pressing the Win + s shortcut.
  2. Type Control Panel and press enter key to open it, or simply click on the first search result.
  3. Click on the View by dropdown menu in the upper right corner and select Category (if the view is not set by Category).
  4. Go to Clock and Region.
  5. Click on Region.
  6. Go to the Administrative tab.
  7. In Language for non-Unicode programs, click on Change system locale... button.
  8. Check the Beta: Use Unicode UTF-8 for worldwide language support option.
  9. Click OK.
  10. Click Restart now.

You should be able to see the characters properly in Eclipse.

0

In my case, just right click on the file you want to change the encoding -> Properties and select Resource on the left side menu. In Text file encoding click other and change to UTF-8. Hope to help you.

change encoding of file

RacoonT
  • 31
  • 5
-8

You may require to install Language Packs: 3.2

Siva Charan
  • 17,940
  • 9
  • 60
  • 95