I have a strange problem. I'm using a Windows laptop and a Mac Air for Android development. I use Eclipse as IDE in both of them, Git and GitHub for source code control, and EGit plugin for Eclipse.
Sometimes I use non-English (in fact, Russian) language for comments. And here some strange things occur: when I'm working on Windows, add a comment in non-English, save the source code file, commit the changes, and open it on Mac, that files goes in gibberish (some problems with encoding). When I do vice versa (work on Mac, add comments in non-English, save file, commit changes, open on Windows), everything is displayed fine.
Why do such strange things take place? Why there is a difference with encodings?
-
1What settings are you using in Eclipse for your files? I'd recommend using UTF-8 (and the same on both!)– Jon SkeetOct 8, 2013 at 14:57
-
If I had to guess, I'd say that in windows it's being encoded using windows-1251 and on your mac it's being encoded with UTF-8.– AurandOct 8, 2013 at 14:58
-
Where can I find settings in Eclipse for saving my files? I thought that Eclipse saves everything in UTF-8 by default...– user2419241Oct 8, 2013 at 15:08
1 Answer
Eclipse uses the platform default encoding by default. These are different between Windows, Mac OS X and Linux.
It is recommended to configure this on the project. Do the following:
- Open project properties (context menu on project > Properties)
- Go to the Resource tab
- Change Text file encoding from Inherited from container to Other and select UTF-8 (the only sane choice really)
- Commit the resulting changes in file
.settings/org.eclipse.core.resources.prefs
The last step ensures that the encoding used by Eclipse for this project will always be the same, regardless of platform or workspace settings.