228

Whenever I add a new html file (or other text file) to the project its encoding is set to Cp1250. I am not sure why, I guess this is probably because my default language in Windows is Polish and I don't want to change it. Anyway, Eclipse says that Cp1250 is a 'default' encoding and I have to manually change it to UTF-8 each time I add anything.

So where can I change the default encoding to UTF-8? I've set the encoding by right-clicking on whole project but it didn't help. I can't find anything in options. It's so annoying...

I'm using 'Helios' release of the eclipse and use it with pydev if that matters.

roschach
  • 8,390
  • 14
  • 74
  • 124
PawelRoman
  • 6,122
  • 5
  • 30
  • 40
  • 1
    I am disappointed that the default isn't UTF-8 (8.5 years after you asked this question!). Wikipedia's UTF-8 page mentions: "Google reported that in 2008, UTF-8 (labelled "Unicode") became the most common encoding for HTML files." Section 3 of the Java Language Spec states "Programs are written using the Unicode character set.". – Pixelstix Apr 12 '19 at 14:45
  • Does this answer your question? [How to support UTF-8 encoding in Eclipse](https://stackoverflow.com/questions/9180981/how-to-support-utf-8-encoding-in-eclipse) – Shadyar May 05 '20 at 03:43

9 Answers9

419

Window -> Preferences -> General -> Workspace : Text file encoding

nanda
  • 24,458
  • 13
  • 71
  • 90
  • 34
    There should be a search box in the preferences dialog. Type the first few letters of the thing you're trying to set (say "enco") and automagically it will display which panes are relevant. Great tip next time for finding one of the many hidden prefs. – Jordan Reiter Sep 20 '10 at 23:15
  • 4
    What Jordan said. I am pretty sure searchable menus are the future of software. – PawelP Jan 04 '14 at 16:07
  • 4
    Check my blog for a complete rundown on all those encoding related settings, including screenshots: [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 15:02
  • 1
    BTW, it might be wise to set the file encoding to UTF-8 on the *project* level instead of (or in addition to) on the *workspace* level, because the project settings are stored on the project itself, which means they will be maintained when you check in your project into version control, or copy it to another machine etc., unlike the workspace settings which are bound to that specific workspace on that specific machine. – Stijn de Witt Apr 05 '14 at 15:06
  • I can't store this on project level. Now I have to tell every developer to make this change in every workspace – ropo Sep 19 '16 at 12:49
  • Note: For avoid text representation problems in Linux with a Windows project use ISO-8859-1 – Dani Mar 19 '17 at 17:48
  • Works fine with default – PurpleSoft Jun 20 '18 at 07:05
57

Nanda's answer wasn't enough in my setup. What I needed to do is:

  • Window > Preferences > General > Content Types
  • Select Text > HTML in the tree
  • Select all file associations, particularly .html
  • Input "UTF-8" in the text-field "default encoding"
dantiston
  • 5,161
  • 2
  • 26
  • 30
BiAiB
  • 12,932
  • 10
  • 43
  • 63
8

For eclipse Mars:

Change Workspace Encoding:

Change workspace encoding

Check a file Encoding: Image check a file encoding

vanduc1102
  • 5,769
  • 1
  • 46
  • 43
5

Preferences >> General >> Editors >> Text editors >> Spelling: Enconding

P.S.: Eclipse Indigo and Juno.

Merphys
  • 104
  • 1
  • 4
5

If you need to edit files of same type with more encodings in different folders and projects (e.g. one project is in UTF-8 and other in Windows-12xx), go to Window > Preferences > General > Content Types > Text > and select each type with multiple encodings.

For each type delete content of the Default encoding and click Update.

This way Eclipse will not "autodetect" encoding and will use encoding set for project or folder.

Radek Pech
  • 3,032
  • 1
  • 24
  • 29
4

I was having the same problem when I received a html to put inside my project and rename it to .jsp. To solve the problem, I needed to what people above already said, that is, to change text encoding in Eclipse Preferences. However, before renaming the files to .jsp, it was necessary to include the following line in the beginning of each .html file:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

I believe this forced Eclipse to understand that it was necessary to change file encoding when I tried to rename .html to .jsp.

2

What worked for me in Eclipse Mars was to go to Window > Preferences > Web > HTML Files, and in the right panel in Encoding select ISO 10646/Unicode(UTF-8), Apply and OK, then and only then my .html files were created with .

Alcides
  • 508
  • 1
  • 7
  • 15
2

To change the default encoding used for all workspaces you can do the following:

Create a defaults.ini file in the Eclipse configuration folder. For example, if Eclipse is installed in C:/Eclipse create C:/Eclipse/configuration/defaults.ini. The file should contain:

org.eclipse.core.resources/encoding=UTF-8

If you want to set the line terminator to UNIX values you can also add:

org.eclipse.core.runtime/line.separator=\n

In eclipse.ini in the Eclipse install folder (e.g., C:/Eclipse) add the following lines:

-plugincustomization 
D:/Java/Eclipse/configuration/defaults.ini

You might need to play around with where you put it. Inserting it before the "-product" option seemed to work.

rghome
  • 8,529
  • 8
  • 43
  • 62
0

Window>Preferences>Web>JSP files

moueza
  • 69
  • 1
  • 7