Search code examples
eclipsecharacter-encoding

How to change the *default* default encoding in Eclipse?


Every time a new workspace is created, Eclipse defaults to Cp1250 encoding.

Whenever I create a new branch of the project, and as result switch to a new workspace in Eclipse, I need to go to Window -> Preferences -> General -> Workspace : Text file encoding and manually switch to "Other: UTF-8". If I forget this step, Eclipse mangles the UTF-8 characters in the project files.

enter image description here

Can I change the default somehow, permanently, so that all new workspaces start as UTF-8 without need to switch them manually?


Solution

  • Actually, it is quite simple:

    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.