Java files became encoded - java

So I'm not sure what the reason is/was, but now (only)two out of my five .java source file are loading in Eclipse as a single row of squares. I opened it in notepad and it showed the encoding (a lot of East Asian characters and I even saw a sun and stuff), but now it only shows squares in Eclipse, and nothing elsewhere.
Can somebody explain what may have happened and offer a solution?

Right Click on the file in Eclipse and select 'Replace With > Local History' Eclipse will show you a list of previous versions of the file (if it has any). You can replace the bad current version from those.
Take the time to set up a backup system. Also use a version control system like Git or SVN to keep good copies of your files.

Try Preferences -> Workspace -> Text file encoding and other UTF-8

Related

Can source code files with different encoding coexist in (the same) Java (project in Eclipse)?

I know Java uses UTF-16 internally and expects .properties files to be in ISO-8859-1 by default.
I'm currently working on a project that was written in Eclipse, whose default encoding on our systems is cp-1252. I'm thinking utf-8 would be a much more sensible option, going forward.
However, given the scale of the project (it's split up into modules and uses libraries from all over the place), I can't just batch-convert all source code files in one go.
Will Java have a problem with some files in a project being in one encoding and some in another? (Clearly, having entire libraries written in encodings that are different from one another doesn't seem to be a problem - probably because they are all UTF-16 once compiled, anyway.)
Would Eclipse be able to handle that (i.e. different encodings per file) correctly?
Yes you can.
You can choose the default encoding to use for the whole Eclipse project:
right click on a project
resource part
Text file encoding zone, check Other and choose UTF-8 (or what you want) in the combo
You can also change the encoding for a particular file:
right click on the file
resource part
Text file encoding zone, check Other and choose UTF-8 (or what you want) in the combo
Preferences are store in the hidden folder .settings in your project. File encoding preferences are store in the .settings/org.eclipse.core.resources.prefs.
Thoses preferences can be commited using your favorite source control and shared with other developpers.

the project was not build since the source file could not be read

I am trying to build an open source android project, but just after build starts, I get this error:
The project was not built since the source file /android/build/tools/droiddoc/test/generics/src/com/android/generics/TestComparable.java
could not be read
I tried everything I found, Refresh > Clean > build / Restart > refresh > Clean > build.
I understand it could be an encoding problem since that file may come from a repository, and was stored on windows or something.
If you know a solution or a possible solution, please help, I am out of ideas.
"The most common cause is an incompatible encoding in the file. I get
these some times on linux when I get a file with cp1252 (or whatever the
window encoding is)".
Try setting your eclipse's encoding to utf8.
I have opened the Project > Properties > Resources > Linked Resources and deleted the resources with error marks, since these links were broken anyway. This solved the problem.
For me there was a different solution than mentioned here.
I was doing a no-no, I imported a project that had a .project file, and there was some errors in the way my version of eclipse was reading some of the files. The package names and files had a little ! symbol with a yellow background.
The solution was to delete the packages. Obviously make a backup. But in doing this most times the files nor the packages were deleted. Instead eclipse refreshed and the desired files were there. Sometimes I had to hit refresh (F5), and sometimes I had to restore files.
I found it best to delete the packages as that is where eclipse was having reading the data.
Project -> Clean... worked for me when a deleted file was not found.

Eclipse opens different source file than the editable one

When I run an application into eclipse, if an exception is thrown and is showed in the console, then you are able to click on the links which takes you to the source code file.
Fine, the problem is that when I click those links they open as external uneditable resources (different icon in the editor tab, Java source files have a blue J but these files have the J empty, only showing the border). Same problem when debugging, the files opened are not the same tabs as the ones edited.
For more information, while the normal source files shows in the title bar something like:
project/path/to/source/file.java
The others show its complete path:
C:\absolut\path\to\source\file.java
This is quite annoying since I have to go and back from one to the other and I have no idea where to change this or why it is happening (it was alright a time ago).
Any hints on how to edit this?
Thanks
It is a classpath problem. When you click, you are actually accessing the file from the classpath.
To view the Java file, you have to add a reference to your project in the classpath and move it to the top of the classpath list.
You can also try converting it to project facets java version, right click on project --> properties --> choose Project Facets -->java 1.7 or [your version]. Apply.

Eclipse plugin for exporting svn diff to JAR

I'm looking for SVN plugin, which can export diff files between 2 revisions to runnable jar file.
So I will give it to another man, who just run it on test/production server, and jar automatically will update project with exported diff files.
It's easy to write command tool like I need, but I'm looking for Eclipse plugin.
If I'm reading this right my issue is similar to yours.
Back in Eclipse 3.2 (ish) in the synchronize perspective, you could select locally changed files, then do File > Export and choose JAR, and it would select the files for you. Now it doesn't.
If you want just the text diff, it's easy. Just use the create patch option.
If you want to create a jar containing the changed files - which I find useful for recording the changes for a chunk of work, or saving the alterations to a branch when I want to work on another, then its possible but unnecessarily laboured. (Works with Indigo)
Exporting changes in eclipse Synchronize view:
Select all of them in the synchronize view
Right Click and choose Show In > Project Explorer
In the Project Explorer that appears, all the files should be selected. Some may be collapsed in their parent package. Use the + to make sure they are all visible and selected.
right click in the Project Explorer and choose Export > Java > Jar File, or drag the files into an explorer window if you want them in a flat directory.
What you want is just not possible (at least, not using SVN / text diffs).
SVN/diff work with text files. The result with diff is a excerpt with only the lines changed in a file (in this class a .java source file). These files cannot even be compiled because they are not java code (even if the lines themselves are).
What you may do is use svn log to check which files have changed, retrieve the associated .class files and use them to patch the server. Do not know if there is any tool that makes that automatically, though (and it is complicated as often the .class files are not commited into subversion).

Files edited outside the ide

If I run a script to edit files outside of the ide I am using, will the ide recognize the changes made to the files?
More specifically:
-IDE: Netbeans 6.8
-Version Control: CVS
-OS: Windows XP
In general, yes. But the form designer of NetBeans considers some parts of the code "private", and you shouldn't modify these parts externally. They are identified by comments in the generated code:
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
These parts are in fact generated from an external proprietary .form file, and having the source code not aligned with the .form code will mess everything up.
Yes it should. Give it a whirl and check it out.
Yes, with some caveats:
If you have those files open, edited, and unsaved in the IDE at the time, then you will need to tell the IDE whether to discard or keep your in-IDE changes.
If you have them open and unedited, then depending on the IDE, you may have to tell it to reload those files (the IDE should warn you that the file has changed since you last opened it).
If you move files around, and your IDE has some kind of project file (that tells it, among other things, where all the files are) and you don't update it accordingly, you may have problems.
Any files that you don't already have open in your IDE should behave as expected, and I would consider it a bug if it didn't pick up the changes.

Categories

Resources