How to support UTF-8 encoding in Eclipse - 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

Related

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.
Can I change the default somehow, permanently, so that all new workspaces start as UTF-8 without need to switch them manually?
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.
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.
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.
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"
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:
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.
Now if you create a new workspace, those tracked preferences will be applied to the new workspace.
If you want to see what is being recorded, in Preferences, see Oomph -> Setup Tasks -> Preference Recorder
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:
PS. the default default of the encoding is a hotly contested issue at Eclipse, hopefully the default default will change to UTF-8 everywhere.
in eclipse.ini add :
-Dfile.encoding=UTF-8

How to enable syntax highlighting for *.handlebars files within Netbeans 8

Perhaps this question might be silly, but I need some help. I did the upgrade from Netbeans 7.1 to Netbeans 8, in order to get more functionality and I'm involved in a project that uses handlebars. The problem is I can not find a way to highlight this file. I've tried to go to tools-> options-> Miscellaneous->file and change the file extension and file type associated with no results.
Can you help me with this issue or give me other alternatives that support web editor handlebars?
thank you
I followed this link and applied the HTML mime type and worked fine.
This are the instructions from the webpage:
Go to Netbeans -> Preferences -> Miscellaneous -> Files on a Mac
or Tools -> Options -> Miscellaneous -> Files on Windows
Leave "File Extensions" as "< Choose the extension >" and click the "New" button.
Type in the extension without the dot.
Select the appropriate file type from the "Associated file type (MIME)" drop down box.
http://www.electrictoolbox.com/netbeans-syntax-highlighting-file-extensions/

Highlight .tpl syntax in Eclipse

I've been googling and can't find a solution for this. I'm trying to setup .tpl files to use either HTML syntax highlighting or PHP syntax highlighting. Has anyone does this, or do you know how?
Thanks
Go to Window -> Preferences-
Then General -> Editors -> File Associations-
Add the PHP Editor to the *.tpl file type. You may have to create the *.tpl type if it doesn't already exist.
You may also have to set the content type for your tpl files in Content Types also under the General settings. Scroll down to PHP Source File and make sure *.tpl exists there as well.
Then you need to restart eclipse to make it work.
Go to Window -> Preferences -> General -> Content Types
Select Text -> CSS, click Add, write *.tpl and save.
Do the step two for Text -> HTML, Javascript and PHP.
I took that from this link. You can get that form there or I give their content below if the anyhow that link doesn't work. It works for me nicely.
steps how to install SmartyPDT 0.9.1
Be sure that the .TPL files are not associated with any content type (file type). In Eclipse,
Be sure that the .TPL files are not associated with any content type (file type). In Eclipse,
Go to Help-> Install New Software
At the Work With section click on the Add... button. Give the new "Site" a name and set the location with http://smartypdt.googlecode.com/svn/trunk/org.eclipse.php.smarty.updatesite/ , then click OK. Go back to the Install New Software window and select the newly added "site". If the "Group items by category" check-box is checked, uncheck it. Now you should be able to see 1 item in the software list named "Smarty Feature"
Select the Smarty Feature, click Next> and from here afterwards it shouldn't be a problem.
If you are prompted that this is an unsigned package, just ignore the warning and install it anyway.
After the installation completes, restart Eclipse and it should be working.
Define a default PHP executable of type 'Zend Debugger' (only if you install vanilla Eclipse PDT):
In Eclipse go to Window->Preferences->PHP->PHP Executables Click on the Add button. Enter a name for that executable definition, for example "PHP localhost", complete the 2 fields which ask you for the PHP executable path (the PHP binary CLI executable) and php.ini path. Be sure that the PHP debugger is the Zend Debugger.
Installing smarty on eclipse kepler fails
(see Install SmartyPDT 0.0.9.1 in Eclipse Kepler).
The recommendation there is to use the PHP Development Tools (PDT) from former eclipse juno version. But in contrary to the recommendation I did not DELETE the mentioned features folder but I just uninstalled the plugins from eclipse itself (Help/About/InstallationDetails):
Uninstall all PDT packages
Restart eclipse
Then follow the instructions in above answer to install the PDT packages from Juno version and then the smarty package.
All these Installations worked without error.
But unfortunatly the *.tpl files are still not syntax highlighted. What to do more?
Our *.tpl file extension is not associated with the HTML editor in Eclipse by default.
Open Eclipse’s preferences.
Expand General from the tree on the left and select Content Types.
Expand Text on the right and select HTML. Click the Add... button below, enter *.tpl and click the OK button.
General -> Editors -> File Associations
Click Add..., enter *.tpl, and click OK.
Select HTML Editor from the Associated editors: section below and click the Default button to the right.

How to change default text file encoding in 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

Eclipse autocomplete not working in some Java files

I have noticed that autocomplete is not working in some of java files in Eclipse.
Also, the files where autocomplete is not working, display a hollow "J" as the icon for the Java file. The files where autocomplete is working, icon for java file is a filled "J"
I am wondering if someone can point out what went wrong all of suddent, why the change in icons and why autocomplete and syntax highlighting is turned-off in the files with a hollow "J" icon?
Thanks.
update
Basically, I was doing what VonC has suggested but Eclipse was not refreshing that it why I was thinking that VonC's suggestion isn't working, after doing a refresh, the problem resolved.
Since this question is highly ranked on Google, I will add a solution to fix general auto complete issue, not for 'hollow J' ones.
Try Window (Windows/Linux) or Eclipse (OS X) -> Preferences -> Java -> Editor -> Content Assist -> Restore Defaults
also
Content Assist -> Advanced -> Restore Defaults
some answers (restore defaults) above do not work for some adt bundle installs as of jan '13.
in those cases, go to
Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced
and tick on the JAVA PROPOSAL options.
In this following picture, MyClass.java has a hollow J, because it is explicitly excluded from the sources to build:
Could you go to the properties of the project, "Java Build Path" Section, "Source" tab and see if some exclusion filter has been set ?
It is usual for instance to define:
**/Test*.java
to exclude at first building any unit-test class (when you have a large set of sources and do not want to be presented with Test classes during auto-completion, or do not want them considered during source searches).
Those with a hollow J aren't part of the build path of the project, so they can't participate in the normal build process and therefore auto-complete won't be enabled for these files (and other Java editor features!). You must add the folders with the Java files to be built to the build path using the 'source path' section of the project properties. This can be accessed by right clicking on a project in the project navigator / package explorer and going to Properties. See http://www.informit.com/articles/article.aspx?p=367962 for details.
Additionally, if the files aren't part of a Java project in the first place, you must create a project and move the files in, or put the files in an existing one. Again, make sure these file are under a source directory as described by that section of the project properties.
(source: teradata.com)
I cope with the issue by deleting the file if autocomplete does not work. Just before copying the source code. Then I have recreated the java file with the same name. Pasted the source code previously copied.
As an addendum to the #VonC answer, make sure that the Java files are part of the Inclusion pattern. I had a case where a build process was creating the project while only including .js files and not the Java files:
You can manually edit the inclusions via the Edit button. In my case, a fix was made to the build script to make it permanent.
Neither Restoring Defaults or my build path (file was already in package directory w/other files where auto-complete was working) fixed problem. Fix for me was to close the file explicitly (right click on file name in tab) and re-open. Interestingly, just re-starting Eclipse didn't work either.
Make sure you have the right directory structure. I believe that:
Hollow J icon beside Java file - will not be build
Normal J icon beside Java file - is a file to be build.
I made a mistake when I created webapp artefact. By default it does not create folder for Java, but for resources. I mistakenly put my sources there.
Have a look - see the difference.
I was able to get this fixed in Visual Studio Code, VSCode but entering crtl-shift-p and typing in clean. When I did that I ran the "Java: Clean Java Language Sever Workspace" command. This fixed my autocomplete issue for me.