5

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?

Community
  • 1
  • 1
SF.
  • 13,549
  • 14
  • 71
  • 107
  • Did the answers provided answer your question at all? Is there any additional information you can provide to help get a better quality answer? – Jonah Graham Dec 16 '15 at 22:28
  • @JonahGraham: They are certainly promising. I have to test them in reality and if I find one working okay, I'll surely accept it (if both work fine, I'll pick the one that was easier to implement). Too many questions on this site have an accepted answer that just doesn't work... – SF. Dec 17 '15 at 00:53

4 Answers4

4

This is one of the key things that Eclipse Oomph was created to solve, the ability to set default default preferences, i.e. preferences set across workspaces.

You can go "whole hog" and adopt using Oomph as a full Eclipse Installer and share the install scripts between your team members. The installer can configure everything from which plug-ins to install, to default preference values, to where to check code out from.

Preference Recorder

However, for now you can simply use the Preference Recorder.

  1. Install Oomph, it is possibly already installed if you are using Eclipse Mars. If not, from the Mars update site you can install "Oomph Preference Management"
  2. Open the preferences page, you should now have a new icon next to Help in the bottom left. It will allow you to turn on/off the preference recorder:

pref recorder icon

  1. With the recorder on, change your preferences you want, in this case your encoding, then press OK. You will then be asked if you want to track the changed preferences across your workspaces. You can change the values in the User Policy column.

select

  1. Now if you create a new workspace, those tracked preferences will be applied to the new workspace.

  2. If you want to see what is being recorded, in Preferences, see Oomph -> Setup Tasks -> Preference Recorder

show recorded

  1. To access the full setup configuration, press the button to the right of the Record Into drop-down (top right of UI) and the setup file will be opened in the editor, where you can do further control and mods:

editor

PS. the default default of the encoding is a hotly contested issue at Eclipse, hopefully the default default will change to UTF-8 everywhere.

Jonah Graham
  • 7,890
  • 23
  • 55
3

This appears to be determined by this code in org.eclipse.ui.WorkbenchEncoding:

/**
 * Get the default encoding from the virtual machine.
 */
public static String getWorkbenchDefaultEncoding() {
    return System.getProperty("file.encoding", "UTF-8");
}

So it is taken from the 'file.encoding' environment variable, defaulting to 'UTF-8' if that is not set.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • I checked the (*system* and *user*) environment variables and I don't have file.encoding set... is it *yet another* set of environment variables I don't know about? Or maybe a version thing (Version: Luna Service Release 1 (4.4.1)) – SF. Nov 09 '15 at 11:56
  • 4
    Presumably you do `-Dfile.encoding=UTF-8` in your eclipse.ini (after `-vmargs`) – Jonah Graham Nov 09 '15 at 12:13
  • I'm not sure what sets it but if you look in 'Help > Installation Details' on the 'Configuration' tab you should see the value in the list. As suggested you could set a value in the eclipse.ini – greg-449 Nov 09 '15 at 12:39
  • Have a look at http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding – Jonah Graham Nov 09 '15 at 12:47
  • 1
    @Jonah Graham is right. Modifying eclipse.ini worked for me on eclipse juno and mars. – Juan Carlos Muñoz Oct 31 '16 at 14:36
3

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.

rghome
  • 8,529
  • 8
  • 43
  • 62
2

in eclipse.ini add : -Dfile.encoding=UTF-8

Fox user9219598
  • 101
  • 1
  • 4