views:

271

answers:

7

How do I make eclipse rebuild the database of classes contained within a project or workspace? This is what it uses to make the "References" menu action work, what it uses for the "Add import" dialog, etc. Basically, it's part of the core usefulness of Eclipse. And now, it's only working for maybe 5% of my project.

I've run into this problem multiple times: something happens with eclipse, either through an OutOfMemoryError because I opened some huge file, or because a workspace just has months of hard usage.

Right now, I'm using Eclipse Galileo on Win32. However, I've had this problem on MacOS as well as with Europa and Ganymede.

In the past, I've trashed my workspace and started again, but today this is not an option. My last workspace backup is from last Friday, but that still means hours of work in restoration. Surely there must be another option?

EDIT: I've used eclipse -clean as well as rebuilt my project. This is a corruption problem somewhere in eclipse, not in my project.

A: 

I would suggest running Project > Clean... on the project. This should cause a compete recompile of the project.

Rich Kroll
Unfortunately this seems to have no effect :(
lucasmo
A: 

You can begin by trying to delete your project (without deleting the sources of course, only the metadata associated with it).

Then you re-import your project into your workspace (since the .classpath and .project are still on your hard-drive)

That way, the all workspace is not affected, only the part concerning the current project.

VonC
The project is checked out via SVN (using the subversive plugin), so deleting the metadata makes eclipse 'forget' it was from a subversion repository. This is what I'm trying to avoid, because the checkout process takes nearly two hours. If there's a way to delete all non-svn metadata, I'd be up for that.
lucasmo
A: 

a) quit Eclipse

b) remove all your project bin / target folders (e.g. with commandline)

#starting from current folder (".") search for folders 
# ("-type d") with name (-iname ) "target" or "bin"
# feed this to xargs which calls 
# rm -rf (remove recursive "-r" and force "-f") 
# with the results from find

find . -iname "target" -type d | xargs rm -rf

or

find . -iname "bin" -type d | xargs rm -rf

c) restart eclipse

Normally is NOT nessary to you remove any project from workspace or to remove .classpath or .setting !

d) clean all projects

KlausMeier
A: 

When this happens I usually have to delete the projects from the workspace, go to command line and rm -rf .settings .profile .classpath and then reimport the projects back in. Sometimes I have to delete the metadata directory (which means I have to reinstall some of my plugins). I have yet to find an actual fix for this. Cleaning the project does nothing to help.

You shouldn't have "hours of restoration" work to do if you just delete the .settings .profile and .classpath. You just need to reimport the projects back in after removing them from the workspace. While an annoyance, it shouldn't take more than 5 - 10 minutes.

amischiefr
+1  A: 

This worked:

  • Export preferences from your current workspace (File->Export->General->Preferences)
  • Switch workspaces to a new workspace
  • Import preferences into the current workspace
  • Import your old project into the new workspace (File->Import->General->Existing Projects into Workspace), choosing "Copy project"

That works for getting the references DB fixed. To get SVN (and presumably CVS) to work again:

  • Right click on project, choose Team, choose "Share project." Choose whichever type of versioning repository you were using and click next. Eclipse should realize that your project was already configured for this and just make you click Finish.
  • Update your sources with the repository.
lucasmo
Good procedure. Thank you for the feedback. +1
VonC
+2  A: 

First exit Eclipse. Next in your workspace directory, delete the .metadata/.plugins/org.eclipse.jdt.core/ directory. Next time you launch Eclipse, it will rebuild all of its internal indexes. Often cleaning of projects doesn't force all of that metadata to be rebuilt.

Adam Batkin
Good point, I had forgotten about that directory. +1
VonC
+1  A: 

If it's just on a project level, I recall that you can simply close the project (i.e. Project -> Close project), then re-open it (Project -> Open project). You shouldn't even need to restart eclipse.

ireddick
This seems to work about half of the time. Thanks, it's a real timesaver when it does work.
lucasmo