How to change default text file encoding in Eclipse? - eclipse

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.

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

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"

For eclipse Mars:
Change Workspace Encoding:
Check a file Encoding:

Preferences >> General >> Editors >> Text editors >> Spelling: Enconding
P.S.: Eclipse Indigo and Juno.

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.

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.

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 .

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.

Window>Preferences>Web>JSP files

Related

Eclipse text editor encoding settings for displaying European characters

I have been searching online for the correct encoder setting for Eclipse's text editor so that I can view special characters such as European ones (e.g. ä, ü, ß, etc.). The files that I am interested in are some SQL script files (*.sql) which I simply edit, but not run from my Eclipse project. My problem is that when I open the files using eclipse editor, those special characters appear as gibrish, but when I use things like sublime or notepad++ they are okay!. I would very much like to avoid that and be able to use eclipse.
I have tried changing the encoding settings using Window>Preferences and etc. settings. My current encoding is set for ISO-8859 (Latin-1) encoding. Does anyone have any experience in this?
You have to know what encoding your *.sql-Files use.
Apparently notepad++ guesses encoding based on the files content, that's why it works in notepad++. You can try to open the file in notepad++, then open the encoding menu and check what encoding the file has. Then go to eclipse and choose the corresponding encoding.
In general I recommend setting the encoding in eclipse to utf-8.
Edit: I tried to reproduce the problem with Eclipse Luna R2 on Windows 7 by creating a UTF-encoded file in my project folder named "test.sql" with a content of "äöü". Then I set the eclipse encoding to ISO-8859-1 and opened the file by right-clicking in Eclipse->Open With->Text Editor. Eclipse correctly displays the "äöü" string.
Could you please provide more information? What Version of Eclipse do you use? What operating system? How do you open the .sql file in eclipse? Double click? drag'n'drop?
Edit2: I could reproduce the problem by changing the project specific encoding settings: Go to Project Properties->Resource and change the Text file encoding to UTF-8. The Project setting overrides the workspace setting.

how can I make the internal editor the default editor in eclipse

I want the default edior to be the internal editor and not the system editor.
I have it configured in window->preferences->file associations to use default internal xml editor for *.xml yet eclipse always tries to open files with OS system editor. How can I prevent this?
The editor type is mapped to file type; you can do this on a per-workspace (global) or per-project basis.
It should be pretty much as simple as this:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.wst.xmleditor.doc.user%2Ftopics%2Ftxprefs.html
Go into "Help, Install Software, What is already installed?" and make sure you have "Eclipse XML Editors and Tools" installed. You you don't, then get it.
Finally, create a new, "clean" project, add an XML file, and verify it works correctly
I found this question but the answers didn't help me, so I continued searching and found the answer here http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-51.xhtml
Basically, in the Preferences, General > Editors > File Associations, then define your file types (if not already there), and select an editor.
Right Click on File from Project,
Select Open with ....
Select your editor

How to support UTF-8 encoding in Eclipse

How can I add UTF-8 support in eclipse? I want to add for example Russian language but eclipse won't support it. What should I do? Please guide me.
Try this
1) Window > Preferences > General > Content Types, set UTF-8 as the
default encoding for all content types.
2) Window > Preferences > General > Workspace, set Text file encoding to Other : UTF-8
Open Eclipse and do the following steps:
Window -> Preferences -> Expand General and click Workspace, text file encoding (near bottom) has an encoding chooser.
Select "Other" radio button -> Select UTF-8 from the drop down
Click Apply and OK button OR click simply OK button
You can set a default encoding-set whenever you run eclipse.exe.
Open eclipse.ini in your eclipse home directory Or STS.ini in case of STS(Spring Tool Suite)
put the line below at the end of the file
-Dfile.encoding=UTF-8
Just right click the Project -- Properties and select Resource on the left side menu.
You can now change the Text-file encoding to whatever you wish.
Right click on main source -> Run As -> Run Configurations -> (x)= Arguments -> VM arguments -> add:
-Dsun.stdout.encoding=UTF-8
September 24, 2022 Update:
JDK 19 (released on September 20, 2022) has System property
stdout.encoding
which can be set to UTF-8, i.e. add the following option to the java command:
-Dstdout.encoding=UTF-8
You can set an explicit Java default character encoding operating system-wide by setting the environment variable JAVA_TOOL_OPTIONS with the value -Dfile.encoding="UTF-8". Next time you start Eclipse, it should adhere to UTF-8 as the default character set.
See https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html
If you have problems with JSON files, it turns out in some Eclipse versions there is an embedded JSON Validator. You can turn it off by doing the steps below:
Go to Windows->Validation and Uncheck JSON validation checkboxes
I tried all settings mentioned in this post to build my project successfully however that didn't work for me. At last I was able to build my project successfully with mvn -DargLine=-Dfile.encoding=UTF-8 clean install command.
You may require to install Language Packs: 3.2

Can I use custom encoding to edit files over FTP in the Eclipse Text Editor

I like to use UTF8 in my projects. It is my default encoding in Eclipse.
But sometimes I need to direct edit some files over FTP.
Is it possible to use Eclipse as remote text file editor of files in non-UTF8 encoding (in general, I need these: koi8r/u, cp1251, cp866)?
Thanks.
You could use Aptana Studio 3 (standalone or as a plugin) or RSE plugin for direct edits over FTP.
To view a file in different encoding use menu Edit/Set Encoding when the file is opened. Same applies to opening local files in non-default encoding.
Cheers,
Max

How to change file encoding in NetBeans?

I want to change encoding of file in NetBeans IDE (ver 6.9.1), let's say from ANSII to UTF-8. How can I do that?
EDIT: I will be more precise. I don't want to change the default encoding in NetBeans. I want to only change encoding of the currently edited file.
Go to etc folder in Netbeans home --> open netbeans.conf file and add
on netbeans_default_options following line:
-J-Dfile.encoding=UTF-8
Restart Netbeans and it should be in UTF-8
To check go to help --> about and check System: Windows Vista version 6.0 running on x86; UTF-8; nl_NL (nb)
In NetBeans model all project files should have the same encoding. The answer is that you can't do that in Netbeans.
If you are working in Netbeans you should consider to convert all files to a single encoding using other tools.
The NetBeans documentation merely states a hierarchy for FileEncodingQuery (FEQ), suggesting that you can set encoding on a per-file basis:
NetBeans wiki article "DevFaqI18nFileEncodingQueryObject": Project Encoding vs. File Encoding - What are the precedence rules used in NetBeans 6.x?
Just for reference, this is the wiki-page regarding project-wide settings:
NetBeans wiki article "FaqI18nProjectEncoding": How do I set or modify the character encoding for a project?
There is an old Bugreport concerning this issue.
Yes, you can change the encoding of a specific file (or see what it has) with this Encoding Support plugin. With this plugin you will be able to handle the different encodings of your files without problems.
Now it is in version 1.4.0 for NetBeans 8.2 and I use it in Windows 10 several time ago.
The operation is very simple, in the status line you can see the encoding of the open file, and from there you can define its new encoding.
On project explorer, right click on the project, Properties -> General -> Encoding. This will allow you to choose the encoding per project.
This link answer your question:
http://wiki.netbeans.org/FaqI18nProjectEncoding
You can change the sources encoding or runtime encoding.
Just try to set the Projects Encoding to "UTF-8" and copy the file (which is encoded in iso) in the same Project (and if you dont need the old file just delete it) - now the copied file will be as UTF-8 - maybe this will help you :)