How to support UTF-8 encoding in Eclipse
Asked Answered
B

12

144

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.

Boles answered 7/2, 2012 at 17:35 Comment(3)
do you want to use translated eclipse or simply change the file encoding?Barbary
Is this about code, or resources? UTF-8 resource support takes a bit more work.Buss
I need Chinese language support in eclipse for Selenium WebDriver tests.Abana
F
289

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

F answered 7/2, 2012 at 17:41 Comment(6)
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 projectsOw
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 ?Finsteraarhorn
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.Geulincx
That is pretty awful... surely the encoding of a project should be dependent on the project, not on the global Eclipse settings?Buss
@Nyerguds: In the Package Explorer, right-click on a project and choose Properties'. The first entry Resource' offers exactly what you want.Xanthus
Why Default encoding of JS Object Notation File not works for *.json?Lott
S
47

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

Snappish answered 29/1, 2014 at 15:2 Comment(0)
D
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

Durware answered 21/2, 2017 at 11:3 Comment(2)
don't advise, cos in my case, when i tried it didn't work, and moreover eclipse started act weird.Drily
@Farkhod Abdukodirov I think file encoding is not an UTF-8 when to set up your eclipse project so it might be a problem though...Durware
W
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.

Waal answered 7/2, 2012 at 17:39 Comment(1)
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.Abana
P
7

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

-Dsun.stdout.encoding=UTF-8
Plagiarize answered 5/9, 2022 at 8:0 Comment(1)
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.Drily
D
3

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
Dowitcher answered 24/9, 2022 at 4:16 Comment(0)
P
1

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.

Piling answered 6/3, 2023 at 7:36 Comment(0)
F
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.

Feebleminded answered 1/2, 2019 at 8:43 Comment(0)
U
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

Uzia answered 3/4, 2019 at 15:31 Comment(0)
D
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

Dialogize answered 5/3, 2021 at 10:21 Comment(0)
L
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

Lemon answered 28/4, 2023 at 2:11 Comment(0)
S
-8

You may require to install Language Packs: 3.2

Selfstarter answered 7/2, 2012 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.