Setting text file encoding per eclipse project - eclipse

I wanted to know if its posible to set a different file encoding per each project I have on eclipse.
I know that I can have different workspaces and set a different encoding for each one, but id like to have all my projects on one, if posible...

Yes you can.
Open the Properties for the Project and select the 'Resource' tab. Set the 'Text file encoding' to what you want.
Make sure that all the files in the project have their Text file encoding set to 'Default (inherited from container)'
You can also set the defaults for everything in a Folder in the same way.

I think it's possible.
1.Select your project.
2.Right click and select Properties.
3.Select Resource menu and you can choose your file encoding.

This is not working with Eclipse Mars, for some file types, as eg JavaScript. For *.js files, the configuration "Determined from content type" is having precedence over the project's Resource configuration.
I've also tried to specify my JS directory encoding in .settings/org.eclipse.core.resources.pref, which is specific for the project, by defining
encoding//src/main/webapp/js=ISO-8859-1, but then again the workspace configuration is having precedence.
I have a development environment with two distinct projects, one in UTF-8 (newer) and anoter in ISO-8859-1 (legacy). I would like to easily switch between them.
One solution I've found was to create two workspaces. It worked, but it seems rather awkward as instructions to other developers. So it would be desirable to really have such configurations on a per-project basis.

Related

Eclipse and netbeans for properties file in a project

I'm wondering if anyone has encountered this problem and how he solved it. I worked in a project where the IDE is not imposed to developpers (we can use Eclipse, Netbeans etc.).
When working with properties file (Java wait for an ISO-8859-1 encoding), eclipse handles them well, but in Netbeans, each national char (éàü etc.) are automatically escaped like this \uxxx. So eclipse users will get properties file with escaped characters, which is really annoying.
It is painful for i18n for instance.
Does anyone found a workaround for this ?
Edit
In Netbeans 8, it's possible to check an option for properties file that allow us to use project encoding. (See comments below).
That's a sane default behavior - properties file are read using ISO-8859-1 encoding by default (How to use UTF-8 in resource properties with ResourceBundle or find some other resources). I think that NetBeans editor lets you edit them using UTF-8 and converts the content on save. You can override this: select the file (for example in project tab), choose Properties from its context menu and make it use project encoding. NetBeans will not perform the conversion then.

What files in Eclipse contains code templates and keyboard bindings?

I have three common workplaces where I use the Eclipse IDE.
A nice trick when using multiple common workplaces is to copy certain configuration files to Dropbox, and link to them in the original configuration location. This way, all settings and changes are instantly available in your other workplaces.
You've got your workspace with a whopping 100 megabytes of files. You've got your .eclipse which is closing in on 200 megabytes.
I would like to know which specific files contain my custom javascript code templates, and which contains my keyboard shortcuts, so I can share these, and only these, with myself through Dropbox.
Ideally, I'd like a list of of certain settings and their locations so I can choose to share more. But I haven't found something like this on Google.
Why am I not just sharing my entire workspace and configuration directory? Well, first, it is crazy big. Second, Eclipse is modular. In some places I use certain modules that I don't use elsewhere. And you all know that modules/plugins are a crazy mess of files and configuration from which there is no escape.
You can try to export Eclipse preferences from one workspace and export them to other workspace. If it doesn't work for your, enter a bug against corresponding Eclipse project.
I figured it out.
You can copy your ~/workspace/eclipse/.metadata to somewhere. Change a preference, and sync your workspace to your backup in order to find out what files are changed.
You'll find that a lot of settings are in ~/workspace/eclipse/.metadata/.plugins/org.eclipse.core.runtime/.settings/. The javascript templates and other javascript options are in ~/workspace/eclipse/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.jsdt.ui.prefs
org.eclipse.wst.jsdt.ui.prefs = Code Templates
org.eclipse.jdt.ui.prefs = Syntax Coloring
org.eclipse.ui.editors.prefs = Text Editors

Eclipse Encoding MacRoman -> UTF8

I recently created a project, organized it and well... I used my Mac with Eclipse running. Somehow it stored everything in MacRoman. The project has to be UTF8.
Is there any easy way to handle the conversions?
You have some detailed explanation in this blog post by David HOLT for the WOLips/WOProject.
Check your default preferences:
In Eclipse, go to Preferences>General>Workspace and select UTF-8 as the Text File Encoding.
This should set the encoding for all the resources in your workspace. Any components you create from now on using the default encoding should all match.
Change the encoding for a resource (project, folder or file)
Right (or Control) click on the resource in the WO Package Explorer and select the Properties option at the bottom of the contextual menu.
Go to Resource>Text File Encoding.
You should see "Inherited from container (UTF-8)" if you've made the change above, otherwise it will be (MacRoman).
Select Other - UTF-8 and Apply to make the warning go away.

Change text encoding for multiple files at once in Eclipse

I have some UTF-8 HTML templates in my Eclipse project and Eclipse keeps treating them as if they had a different encoding. It says the encoding is "determined from content". I want to force the correct encoding.
I can force it for a single file but setting an encoding for the parent folder won't affect the files in it because instead of the "inherit" option in the property sheet there's the "determined from content" thing in it's place.
Is it possible to set the encoding for all files in a Project at once?
I've just solved this problem (eclipse 3.5.2)
Two steps required:
Change text file encoding on the folder property page(.setting/org.eclipse.core.resources.prefs file has been created in my project)
Change default encoding on *.html file content type on the Preference page General/Content Types
I've only seen "determined from content" for XML files. In that case it's the only correct setting, because XML files have their encoding defined in their header, so forcing anything else would be a grave mistake.
If you still want to do it, you could try to view the file .settings/org.eclipse.core.resources.prefs in your project (that file may or may not exist dependin on wether you've manually set any encoding in the project or not).
This was caused by a development version of Eclipse. In the latest official release (3.5) it is fixed.

Eclipse syntax highlighting preferences save and restore

I spend some time customizing the colors for syntax highlighting in Eclipse (Java, JSP, HTML, CSS, etc.) but whenever I try to export these settings via File|Export|General|Preferences and reimport them, the settings never completely get imported back. Some colors are restored and others are left unchanged, leaving me in an 'in between' state - very frustrating.
I'm using Eclipse 3.4 Ganymede, by the way.
Has anyone found a reliable way to save and restore Eclipse syntax highlighting settings?
I finally figured out how to do this.
I just wanted to mention beforehand that I did try to start with a fresh Eclipse install, export the preferences to a .epf file, change just one single setting, export again, and compare the files. To my surprise, trying to import settings from a minimal .epf file did not work reliably either.
The solution that worked for me was to copy these files: {Eclipse workspace directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings/*.prefs
I tried a fresh Eclipse install on another machine and after copying those files over, all my settings were restored perfectly.
The solution was to copy SOME - not all - of the files from {workspace}/.metadata/.plugins/org.eclipse.core.runtime/.settings/*.prefs into my other workspace.
In particular (per the https://stackoverflow.com/questions/96981/color-themes-for-eclipse thread):
org.eclipse.jdt.ui.prefs = Syntax Coloring
org.eclipse.ui.editors.prefs = Text Editors
Copying other files caused things to break.
There are a couple of notes to add:
I had to copy the aforementioned pair of files several times before I got the correct syntax coloring.
Be sure to close the workspace, if it's open in Eclipse, before copying the files.
This worked with Eclipse Helios.
If you want to be a little more fine grained on what you migrate, the syntax highlighting rules are the lines starting with semanticHighlighting on workspace-indigo/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs
Doing this, I was able to migrate my syntax highlighting from Helios to Indigo
I'm using JBoss Developer Studio 10 with the Eclipse Neon 4.6 engine.
All .prefs files are inside this path:
/workspace/.metadata/.plugins/org.eclipse.core.runtime/.sett‌​ings
Update: I found a similar structure on this path too:
\RedHat\JBossDev\studio\configuration\.settings
It's my IDE folder plus \configuration\.settings
I recommend search for org.eclipse.*ui*.prefs instead *.prefs to refine your result.
The principal config files are:
org.eclipse.jdt.ui.prefs
Java Syntax Color Settings
org.eclipse.ui.editors.prefs
Text Editor Settings
org.eclipse.cdt.ui.prefs
Formatter Settings
org.eclipse.wst.jsdt.ui.prefs
JavaScript Syntax Color Settings
org.eclipse.jst.jsp.ui.prefs
org.eclipse.wst.css.ui.prefs
org.eclipse.wst.html.ui.prefs
org.eclipse.wst.json.ui.prefs
org.eclipse.wst.dtd.ui.prefs
org.eclipse.wst.xml.ui.prefs
org.eclipse.wst.xsl.ui.prefs
If have a problematic workspace:
Copy the files above
Create a new workspace
Copy and Replace that files in your new workspace
This will recover perfectly your custom editors color settings. For me worked very well.
Eclipse CDT stores 'Syntax coloring' in the file org.eclipse.cdt.ui.prefs
This is located for example here: C:\eclipse\workspace.metadata.plugins\org.eclipse.core.runtime.settings\
Copy and paste over the top of the one in your new eclipse instance. This worked for me when moving from 3.4 to 3.5
I would export the preference before modifying the color, and then after.
That way, you would be able to isolate the specific rules of an eclipse preference file into one smaller file and:
check if some colors not restored are indeed represented by a rule
the import of a smaller preference has any effect on the previously unchanged settings.
That kind of strategy can be further refined into several small settings files (one for Java, one for JSP, HTML, CSS, ...), in order to better analyzing the potential side-effects when re-importing those settings.
I have had success in importing Eclipse Helios's syntax highlighting rules by copying the file:
.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs
from the source workspace to the target workspace. It seems this file also contains Eclipse's code formatter profiles and code templates.
Environment:
Version: Helios Release
Build id: 20100617-1415
(on linux)
Once Michael Bosworth's answer helped me to some extend and I voted up. But now I see some obligation to answer it myself, because copying these two files are not enough. Let me explain why.
First, these files contains lines irrevelente to syntax coloring.
Second, syntax coloring for other editors are located elsewhere, for example, those of XML files are in
org.eclipse.wst.xml.ui.prefs
and those of HTML files:
org.eclipse.wst.html.ui.prefs
JSP pages?
org.eclipse.jst.jsp.ui.prefs
, etc.
Third, when we change font colors, usually we change background colors, line highlighting colors, etc. to get a clearer view of codes. This involves more files.
If we search *.pref files in path
/workspace/.metadata/.plugins
we can find all preferences files where we can locate all lines of coloring settings. But by copy-pasting all these files to another workspace can also trigger problems, for they are not exclusively syntax-coloring-related. Moreover, when we are switching between two versions of Eclipse, unexpected problems may arise.
So, the safest way is:
Create a new workspace if you don't have one.
Open all *.pref files we find in the workspace one by one,
Copy those lines containing color codes,
Find the same file in your new workspace,
Replace the color part by existing one. Or, set the colors in Eclipse, by assuming the corresponding options according to properties' name. All color codes are RGB based.
EDIT: (2017.02.24)
Eclipse Mars has a plugin Oomph, which can record your preference settings to provide seamless transmission of your preferences. When you activate it, every time you change a value, it prompts to ask you if you want to record it in Oomph, providing you the exact line in the corresponding file where your new value is stored. So, when you install Oomph, you can:
Change the settings of your font face, font size, background color, etc.
In the prompt windows of Oomph, take note of the location of your new settings. (Because if you tell Oomph to remember your settings, it will not prompt never again, so you may only see this windows once.)
I have deleted recently changed *.prefs file from the following dreictory \myworkspace.metadata.plugins\org.eclipse.core.runtime.settings\ and imported existing exported preference.
I am the first person, who answer for this question as per my knowledge :), Cause even I struggled lot.
Thanks
I faced the same problem few days ago.
The easiest way to restore the defaults is to import the default theme again, which you can find under:
http://eclipsecolorthemes.org/?view=theme&id=790