Skip to content
Advertisement

How to change a default charset for Java machine in Eclipse?

I am finding any elegant method, how can I change default charset of Java machine to UTF-8 in Eclipse. I have found many methods, how to do from source code, but I would like to know, how to do it fast, easy, from Eclipse IDE without writing java source code. Thanks.

Advertisement

Answer

You can change the workspace default encoding for all files in the Preference page Workspace, about the bottom left of the dialog. All new projects and files will have that encoding.

However, if you are using existing projects, be vary of three things:

  1. Existing files saved with a different encoding might need conversion; it will not happen automatically.
  2. Projects (or files or folders in projects) might have alternative default encodings (set Resource page of the Properties dialog). Those settings are more specific, and will not be affected by the generic workspace settings. Furthermore, these settings are shared with the project, e.g. through version control, so if you collaborate with others, make sure to set up encoding together.
  3. This is not Java specific; there is no supported way to do it only for Java projects.

Edit: as you want to edit the default character encoding for your application, see the answer Setting the default Java character encoding?

In short, you have to set it up as a JVM parameter, like

java -Dfile.encoding=UTF-8 … com.x.Main
Advertisement