Eclipse: How to set file encoding based on file extension - eclipse

Problem
I have an eclipse project that is committed to source control.
The project looks something like this:
MyProject
.classpath
.project
src/
com/myCompany/code
DoStuff.java
DoOtherStuff.java
someText.foo
conf
someOtherTextFile.foo
As you can see we have files of file extension foo. The foo files use a different file encoding (ISO-8859-1) then the rest of the files in my project. I want to configure eclipse to use ISO-8859-1 whenever those files are opened.
Here are the options that I have found so far:
Solution 1 - Mark each file one by one
Right Click File -> Properties -> Text file encoding -> Other: ISO-8859-1
This then adds a line to .settings/org.eclipse.core.resources.prefs:
encoding//conf/someOtherTextFile.foo=ISO-8859-1
This solution works ok, but I need to do it for every foo file in my project and I need to make sure that no one ever forgets to do it when they add a new foo file.
Solution 2 - Configure it in my workplace settings
This is done like this:
Open the Eclipse Preferences and go to 'General > Content Types'.
Select the type of the file, for example 'Text'
In the File Associations area click 'Add' and add '*.foo'. Enter
'ISO-8859-1' in the 'Default Encoding' field.
Click OK and you should be set.
(Thanks greg-449 for clarifying how to do this).
This solution does not work for my team because we don't commit the Eclipse workspace settings into source control (we only commit the project settings).
What I really want to do
I would like to be able to say that all files in the project ending with .foo should be displayed with the encoding ISO-8859-1. I need to configure this at the project level because my team commits project settings into source control but not workspace settings.
Any hints on how to do this?

Greg-449 already explained you the steps, I am pasting the same explanation with screenshots:
Windows -> Preference -> General -> Content Types -> Text ->Add -> *.foo -> ok -> click on *.foo and fill the Default encoding as 'ISO-8859-1' -> update -> ok

Related

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/

Eclipse: automatic file opener plugin

I'm searching this feature (or plugin) in eclipse:
a prospective "project oriented" that remembers opened files, and when I open/switch another project eclipse closes all file of the last project selected and open files previously opened of the new project selected
use case:
I select Project1 -> [eclipse closes all file actually opened]
I double-click on file1 in Project1 -> [eclipse opens this file]
I select Project2 -> [eclipse closes file1]
I double-click on file2 in Project2 -> [eclipse opens this file]
I select Project1 (again) -> [eclipse closes file2 and opens file1]
there is something like that??
thx in advance
p.s. i'm sorry for my english -.-'
I think, the task-focused interface of Mylyn is closest to your goal. In Mylyn, you can save a context (a list of opened editors, or even positions in editors) to a task (or ticket, etc.), that can be shared.
When you want that context again, you switch to that task, and it will provide you with your old context.
Check out the Eclipse plugins at http://andrei.gmxhome.de/eclipse.html
In particular, look at "Extended VS Presentation" and "AnyEdit". The first one lets you manage lists of open files, and the second one includes an import/export feature for working sets.
I tried Mylyn, but I did not like it. I want explicit control over my file sets, and Andrei's plugins provide what I want.

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

How do you make NetBeans ignore files when searching for files?

In NetBeans when you go to Navigate -> Go to File you can search for files by filename. Is there a way to instruct NetBeans to ignore some files. It's picking lots of files from a tmp directory in my project which I never intend to open and it's just noise.
You can also add folders to the "Files ignored by the IDE" configuration.
Select Tools|Options and add the folder names to the regex.
NB: I have not yet confirmed that this achieves what is described.
In NetBeans 7 you go to "Project Properties" then to "Ignored Folders" and you just add your folders there.
You can configure include/exclude file patterns on a project by project basis. This feature will allow you to add an exclude pattern for your 'tmp' directory, which will stop 'Go to File' suggesting files contained in this directory.
To configure bring up the project properties (File -> Project Properties), select sources, and click 'includes/excludes' button. I.e.:
In my version of Netbeans (6.9.1 on Win 7), there is no button under Project Properties -> Source in which to enter exclusion patterns.
You have to go to Tools -> Options -> Miscellaneous -> Files and add the necessary file names or extensions under "files ignored by the IDE" in the Ignored Files Pattern field regexp.
For ignoring an entire folder, it is (in my version) on the project properties screen, but not under Sources; instead look at the "Ignored Folders" category.

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.