0

I recently bought a new computer so in the process of backing up to time capsule, reinstalling eclipse and reloading my project Eclipse came up with the usual "import Foo cannot be resovled" error. I added my /WEB-INF folder to the classpath, refreshed, cleaned etc to no avail. I decided to delete the project (and DID NOT click the checkbox saying delete project contents on disc). I reset up the project using the sources from my server (on a shared computer). Still having no joy I looked inside my classes folder to find it empty.

So I ran to my server to find that indeed my classes folder is empty, I went to the trashcan to find no java or class files, I did a full search of my mac and my macbook to find no class or java files. The compiled classes are still working, but I'm scared that they'll disappear on the next restart - does anyone have any clue how to get my class source code back? They represent over a year of work. I had version control but only on this computer.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kimberly-Ann
  • 27
  • 1
  • 2
  • 2
    This is not really Java or development related but more of an issue related to Apple products. – Shivan Dragon Oct 24 '11 at 17:26
  • I gather that it's a "Dynamic Web Project" which resembles a WAR. I only don't understand the source code loss problem as you told that the sources are available on the server on a shared computer? How exactly did you import the project? Straight from shared computer as network disk or from a copy on your local disk file sytem? What Java code imports exactly are unresolveable? Do they happen to be of `javax.servlet` package and likes? Are you sure that you've "Eclipse for Java EE", not just "Eclipse for Java" and that you've setup the right server before importing the project? – BalusC Oct 24 '11 at 17:33
  • craaazy. are you sure the project was there with all source code before you deleted it from eclipse? – MarianP Oct 24 '11 at 17:33
  • The source code is on the shared computer and the project referenced the files straight from the shared computer. All files in the 'classes' folder and the 'src' folder are gone, but war files in the 'lib' folder are still there. javax.servelet is still there, the files are my own packages. The server was never touched, the laptop I was working on is the new one. All I can think of is that in the process of deleting the eclipse project my files were deleted. – Kimberly-Ann Oct 24 '11 at 17:44
  • Just rebuild the project? Note that `/WEB-INF/lib` should **not** contain WAR files nor servletcontainer-specific libraries. – BalusC Oct 24 '11 at 17:52
  • I don't know, but maybe you created the workspace inside the eclipse installation dir... ? I think eclipse sometimes uses that as a default dir. Or used to anyway. – KarlP Oct 24 '11 at 20:25

5 Answers5

2

Start with copying the .class files to a separate folder, so you won't lose them too.

The try to find your backups using time capsule or whatever.

If all else fails, decompile the .class-files using a tool.

How do I "decompile" Java class files?

I don't know it it makes you more happy, but you are not the first one that magically looses the source code of something important... With or without backups and version control...

Community
  • 1
  • 1
KarlP
  • 5,149
  • 2
  • 28
  • 41
  • I like this idea. Would have tried it if i hadn't found the restore from history (as opposed to refactor...history). – darKoram Aug 13 '12 at 23:00
1

Many Many people use eclipse every day and if this was happening regularly I'd expect that the problem would be pretty loudly reported--the problem is more likely to lie in your process (although eclipse WILL delete your source directory if you tell it to delete the project then select the "Delete source" option and confirm it)

You are at the point in every programmers life where we learn about the advantages of Version Control. Embrace SVN or GIT, even for a single user project. This has cost us all at some point, and from then on using version control becomes as innate as pressing ctrl-s every 20 seconds.

As for your current situation, go back and analyse your time capsule backup, find a recent backup that works, restore it again then stick it into version control. If you haven't set up version control before, SVN is wonderful and easy to configure.

TimeCapsule is good, but it's no substitute for a good vc system.

Bill K
  • 62,186
  • 18
  • 105
  • 157
  • Thanks Bill K, I know you're right. I do have older versions of my source code that I can sit and update but I'm heartbroken right now! Source control was one of those things that I thought 'I'll read up on it soon so that I understand how to use it properly' - I guess that time is now :( – Kimberly-Ann Oct 24 '11 at 17:46
  • Ah, but then all is not lost! You'll find that rewriting the changes you have made since the last backup will go quicker than the first time, and it will be better code too :-) – KarlP Oct 24 '11 at 17:53
  • Thanks KarlP, thats true - after all theres always code I want to improve 'when I get around to it'. I needed that :) – Kimberly-Ann Oct 24 '11 at 18:17
  • @KarlP That's exactly what happened the first time I learned about the need for version control! I lost my entire 3-months project and was about to turn in my resignation notice when I remembered that I took it home that weekend (on a floppy) to work on it. I still had the copy at home and was able to catch up in less than a day, and my code was significantly better after the re-write (always is)! – Bill K Oct 24 '11 at 19:24
0

I just had Eclipse add a second src file to my project. I was adding a jni folder and did a rename refactor of one file in the src directory. So i got two src folders with a red x on them. I deleted one of them and got no dialog asking if i wanted to delete from disk. However, Eclipse did just that. Both src folders disappeared. It's not in my trash can. I agree with the original posting. Though i have been using eclipse for 2 months and this is the first file system error of this sort i've encountered, there is definitely a bug there. it would be nice if eclipse deleted files to the trash or offered recovery tools. The History... gave me no options to recover.

darKoram
  • 1,113
  • 1
  • 14
  • 25
  • Well, although Refactor->History is a dead end, the advice at http://www.nodans.com/index.cfm/2008/1/18/How-to-recover-a-deleted-file-in-Eclipse to r-click the project and choose "Restore from History" did indeed work. However, i end up back with two src folders. http://www.sunfarmkitchens.ca/?q=webfm_send/78 . Interestingly, they are duplicates except that one has a package named A.B.C while the other is nested files A/B/C. Same contents. Something in .metadata got screwed up? – darKoram Aug 13 '12 at 22:58
0

I know this was a long time ago but if you right click on your package or project and click 'restore from local history', you can restore your files no problem.

JHurst
  • 45
  • 1
  • 10
-1

Yes, significant problems should occur widely and get reported frequently. However I have reason to believe there can be rare problems. I don't keep project source code in my eclipse workspaces, but use a common folder structure to mirror our SVN repository. The other day I had an eclipse workspace open on 5 of the projects (out of about 25) and did a maven build. All was successful and eclipse looked fine. After testing elsewhere, I came back to eclipse about half an hour later and saw red problem indicators all over the project explorer. On traversing the projects, I found all the source folders and files had disappeared. Only the project folders and their compiled class folders had survived. This applied to all projects my workspace had been connected to. The other 20 projects had been completely deleted, as had my build areas that theoretically only ANT knows about. The pattern of deletion is far too subtle to be cause by me accidentally clicking a button or dragging something.

Graham
  • 3
  • 2
  • It's a good suggestion to mirror the structure, and keep the code in a separate location, but I'm not sure this answers the OP's question which was "does anyone have any clue how to get my class source code back". – Ian Clark Jul 25 '13 at 10:44