My java source files cannot be commited - java

i am creating a small Java project and wish to put in on GitHub using eclipse.
Everything is working fine until i go to Team -> Commit, my source files aren't there.
I don't know what to do so i could commit my .java files, any ideas?
Here is a screenshot:
As you can see, there were about 4 files in the Files section, but none of them were the java files.

It is possible you skipped the "add to the index" part: you need to add files, before committing.
See Track Changes.
Click Team > Add to Index on the project node. (This menu item is named Add on older versions of Egit.)
If you don't add anything, the commit will be empty.
See also "Git Basics - Recording Changes to the Repository".

Related

Intellij - Git status shows files have been changed when they have not

I am working on a Java project in Intellij that uses git. Quite a few files are blue (to show that changes have been made), however when I right click them and click on "Git -> Compare with Latest Repository Version" it says that the contents are identical. Anyone know why this happens? It only seems to happen to files that I've opened to look at but haven't changed. Could it happen if I accidentally added extra white space and then deleted it or something? Or just extra whitespace in general?
This is how GIT is different from SVN. GIT's change detection algorithm does not depend only on the content of the file but the meta data (timestamp last modified, etc) of the file as well. So even if you are adding just one space and removing it later on; if you save it, it modifies the metadata of the file.
For more details, you can have a look at: What algorithm does git use to detect changes on your working tree?

Use a Java file that is in a different place than the rest of the project

I have a java source file in my project, that I want to move to an entirely different location than the rest of the files (my unix home dir), but I still want to be able to properly use it in my project. Is there a way to do this?
EDIT - I see there is a vote to close this for being unclear, so - let's say you have a pJava project in Eclispe. All the source files are neatly saved in their relevant packages, under the same directory. Now, I want to move one of the files to somewhere completely different, but still have it used in my project. I hope this clarifies
Thanks!
I suggest that it depends on what your reason is for moving the source file.
The Java file is still conceptually part of this project, but you're moving it for general organisational purposes. In which case, the new "completely different" directory is another place where sources should be read from, which most IDEs will call a "source root". You should configure your project to read sources from there as appropriate for your IDE.
You're moving the file because it's distinct from this project. In which case I would suggest it ought to be a separate project in its own right. In order to still use the logic in your original project, you'd build the new project into a JAR, and then bring in the JAR as a library dependency (either directly, or using some dependency management system such as Ivy/Maven/etc.). Again, the details will depend on what your current setup is.
Right click on your Eclipse's project -> properties -> java build path , and under the source tab click Link source then choose the parent folder of your java file .

Eclipse - Source not found

I know this question has been asked many times before, but none of the proposed solutions resolve my issue (or I'm not implementing them correctly).
I'm developing a plugin for OpenFire, and when I set a breakpoint in my plugin source Eclipse reports "Source not found". The JAR is built separate from the build of the OpenFire server. I've tried adding the JAR and specifying the source code directory, but no dice.
Here's the process I'm following: When I hit my breakpoint I'm clicking "Edit Source Lookup Path", clicking "Add", Java Library, User Library, click User Libraries, adding my library (tried both "Add JARs" and "Add External JARs"), and then specifying the folder that contains the source code. I've also tried:
Adding the source by selecting "File System Directory" instead of "Java Library"
Adding it by selecting "Workspace Folder"
In the Project Explorer, adding the source for my plugin to the Java Build Path
In the Project Explorer, adding my JAR as a Library and specifying the Source attachment
Thanks in advance for any suggestions.
Personally, I have no good experience in Eclipse JDT, when adding a source folder at the time it hits a break point. What I always prefer to do, is adding the source folder before debugging:
Select Project/Properties/Libraries
Select your library and "edit..." the source attachment
Select either the corresponding source folder or the zip/jar containing the package
After that, you should be able to open the source files in the virtual "Referenced Libraries" folder (directly below the "JRE System Library" folder inside the project), or when opening a reference to a linked class file from within the JDT editor. If you are able to access the source, then you should also be able to at least stop at the break point and see the corresponding source.
Else, you will have to check again, if the source folder is really valid: The source folder or source archive must contain the folder with the name of the root package of the library (e.g. the default Java "src.zip" inside the JDK folder also includes a corresponding "java" folder at its root). When in doubt, extract the archive and select the parent folder of the package you are interested in - sometimes source archives might be a mess or incompatible to JDT.
If this has been assured and it still doesn't work, chances are, that your linked source folder does not correspond to the compiled version of the library. Usually JDT will handle such inconsistencies fine, but if you try to open a source file, that is entirely different than the corresponding class file, you will encounter problems. In this case I would suggest either downloading the correct source version of the library, or recompiling the library from the source, if all else fails.
If opening a referenced source file from withing the JDT editor does work fine, and you are still unable to open the source files when a break point is entered during debugging, then most likely the class files are missing the line numbers of the corresponding source file. Again, you will have to recompile the library from the source in this case.
Finally, it is also possible to overwrite the default source lookup by specifying source folders or archives in the source tab of the launch configuration. But you should normally not need to do this, when your build path is configured correctly. From the Eclipse Help:
The Source tab defines the location of source files used to display source when debugging a Java application. By default, these settings are derived from the associated project's build path. You may override these settings here.
I had this very annoying problem for a long time but was finally able to solve it. In my case, a null pointer exception was being thrown somewhere in Java's Transformer.IsRuntimeCode(ProtectionDomain) function.
I didn't really need to know about this since the exception was being caught and handled, but eclipse would pause debugging every time this happened and tell me that the source wasn't available. As a result, I constantly had to keep pressing the button to continue code execution.
In order to prevent this from happening, I:
1. Clicked on the "Breakpoints" window at the bottom of the debugging
screen
2. Right clicked "NullPointerException"
3. Unchecked "Caught"
This prevented the debugger from pausing program flow during a caught NullPointerException.alt text
(source: SharpDetail.com)
And this another one as:
Eclipse doesn't crash. You're trying to step into a method, where eclipse doesn't know where to find the source (*.java) files and informs you about this. Here is how to tell eclipse where to look. Go to
Window->Preferences->Java->Installed JREs,select the JRE you are using and click Edit.
There, select all of the jar files in the list you see and and click Source Attachment....
In the window that shows up, select the fille src.zip, which is in your JDK folder (if you didn't uncheck it while installing the JDK). On the machine I'm on right now, that is
C:\Program Files\Java\jdk1.7.0_07\src.zip.
Save all your changes (possibly restart eclipse) and you won't see that error again.
Well it turns out the solution was anticlimactic. When Balder's recommendations did not work I tried debugging one of the stock OpenFire plugins and it worked just fine. I then created a new plugin from scratch, and by doing nothing other than adding the source to the project (Right-click on the project -> New -> Source Folder) it also worked just fine. I have no idea why Eclipse refuses to see the source for my original plugin, but I moved all my code and libraries over to the new plugin and debugging is working as expected.
Many times you put jar files in eclipse IDE as referenced libraries when binary version of application was downloaded. Usually done so by configuring the build path. But the binary does not have the source files. You have Binary version and source version of application.
One simple way is to download the source libraries that you also use maven to build the project.
Keep somehwere, may be inside your project workspace.
Now while seeing the class file (from eclipse, jar exploded) you may see the source not found, fine.... there is a button below and click on that, a new window opens and there select add external folder.
Reference it to the src folder of the source you downloaded(not the binary one) and kept somewhere as said above and it will show the class details from that.
I fixed this issue with doing the following:
Click at the menu Window - Preferences - Debug - Step Filtering And check all the packages like the following image.
(Step Filtering)
Then, debug again your project and thats it.
Best regards,
In my case, I had a breakpoint in the class declaration. I mean in the next line.
public class GenerateInterface implements JavaCall {
So, the debugger stopped in that line and showed the following message:
Source not found
I think unconsciously activate the breakpoint in that line.

In intellij, How to see SVN log/history of a file renamed or moved before previous commit

In intellij, my project is under SVN control, I have renamed and moved a file then I commited it.
How can I show log/history of this file after this commit with intellij.
"renames and moves are done as a delete followed by an add" via http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-rename.html
so this file lost its previous history.
If you know where this file was previously, right click on the directory which contains this file and in SVN context menu find something like 'show history'. It will show you all changes made in this directory, so you can find this specific file.
I find it. As the source file was rename, the subversion history will not show revisions with the old name.
To see old revisions before and after rename the file in intellij, right click subversion> compare with...
You can then compare the correct revision, with revision before rename the file.

Restore Deleted Files in Eclipse IDE

Two days ago, I deleted five Java files in Eclipse IDE and now I need them. I tried to restore them from the local history. I restored only two of them. When I right click on the other files and then click restore from local history, I get the error message No additional members found in local history. How can I restore those three files?
You can use the information in this Java Tips page (archived)
I deleted my src folder, and used the following steps to get it back:
Select Project
Right Click
Select Restore from local history in the context menu
Select your files,
Click OK.
Steps to recover the deleted files:
Go to the project.
Right click on the project.
Select restore from local history.
Select the file/files to recover.
Please see the attached image:
.
If you still have the binary form (.class), that is you only deleted the source code, then you can decompile then back to source.
Search on Google for some decompilers, for example Cavaj.
Go to Eclipse Menu Bar , and click Edit, and then click Undo Delete Resource. Each time you click "Undo Delete Resource" it brings back resources that have been deleted. I am not sure if you can recover deleted resources, if you try to recover after the machine has been restarted since you deleted your resource.
You don't wanna run into this several times, to be safe please always use version control like Git, SVN, Mercurial.
Answer: You can't.. sorry :\
If restoring from local history does not work, then you are likely out of luck i'm afraid.
my suggestion is be more careful when deleting and use a Source Control Management software like SVN or Git, so you can version your files to prevent things like this from happening again.
In case you are using VCS like SVN or GIT you can just recreate the file with same name and in the same location that's enough.
It is very simple. You can use these steps:
Right click on the project of which you want to recover.
Select restore from local history.
Select the file/files to recover plus version too.
When you see the "No additional members found in local history" message
while trying to retrieve the files after right-clicking a parent folder or package,
try right-clicking the next immediate parent folder or package in the project (or the project itself as mentioned above).
When I right-clicked the next immediate parent folder;
I was able to restore deleted files in a similar situation.
You can use the information in this Java Tips page.
I deleted my src folder, and used the following steps to get it back:
--> Select Project
--> Right Click
--> Select Restore from local history in the context menu
--> Select your files,
--> Click OK.
--> Then go to your git and do "git checkout filename"
--> This should fully restore the file and its content
I hope this helps

Categories