原文地址:
http://www.eclipsezone.com/eclipse/forums/t61566.html
In my time helping people with their Eclipse installs I have seen time after time situations where a crash of Eclipse, the VM or the computer or even just long months of development have started to wear down the stability of the workspace where Eclipse stores everything. If you have time some day, take a look at the <workspace dir>\.metadata directory to get an idea of just how much Eclipse generates and stores in your workspace. Every time you add a plugin, upgrade a plugin, remove a plugin that puts and changes information in your workspace, much like your Windows registry as you install/upgrade/uninstall software on Windows.
Over time you may begin to notice strange behavior in your plugins while using them. Clicking "Search" doesn't actually do anything, autocomplete no longer works or pops up strange results, you just installed a new plugin that is suppose to be stable and it doesn't work at all; what is going on? Chances are your workspace has gotten into a state where, for lack of a better technical understanding, has collected a lot of dust and it is time to clean house.
Using the -clean argument
The easiest way to fix up a dusty workspace is using the -clean command line argument to the eclipse.exe executable. Let's take a look at what the Eclipse help docs tell us this command does:
if set to "true", any cached data used by the OSGi framework and eclipse runtime will be wiped clean. This will clean the caches used to store bundle dependency resolution and eclipse extension registry data. Using this option will force eclipse to reinitialize these caches.
The -clean argument is a one-time use flag, meaning after you have run Eclipse using it, you can remove it until you need it again. If you prefer to leave it set the only side effect of using it ever time are increased startup times (2-3x longer) which some folks do not mind.
Now, back to the description above, this may not sound like much, I have to say that you would be amazed at what using -clean can fix up sometimes; some really random things. There are three easy ways you can go about using this argument:
Edit the eclipse.ini file located in your <Eclipse install directory> and add it as the first argument on the first line.
Edit the shortcut you use to start Eclipse and add it as the first argument.
Create a batch or shell script that calls the Eclipse executable with the -clean argument. The advantage to this step is you can keep the script around and use it each time you want to clean out the workspace. You can name it something like eclipse-clean.bat (or eclipse-clean.sh).
My preferred way to handle this is #1 only because I don't do this very often. I open my eclipse.ini file with any editor, add -clean as the first argument, save the file and restart Eclipse. After this step is done I remove the argument from the file, save it and exit from my text editor.
Creating a new workspace
Now let us say that using -clean didn't help, things are still acting strange, the next step to recovering a stable development environment is to create a new workspace and re-import your old settings and projects into it. As many times as I have seen using -clean solve the most obscure problem or dirty workspace I have seen it not make a lick of difference that only a new workspace would cure.
If you find yourself in the situation where you need to create a new workspace, don't fear, since Eclipse makes exporting and importing your preferences and projects the only time consuming part of this task is clicking a lot of OK and Finish buttons.
The first step to creating a new workspace is to get everything you need out of the current one, that means our preferences. You can accomplish this by going to File > Export... > Preferences > "To preference file", give it a name > Finish . The default at the top of the dialog should have been to Export all , if it wasn't, be sure to select that before clicking Finish. Also make sure you are exporting to a file to a neutral location, like your Desktop.
After we are done exporting our preferences use the File > Switch Workspace command to specify the location of a new workspace and then click OK . After Eclipse has restarted the first thing to do is pull in your old preferences. Go to File > Import > Preferences > "From preferences file", select your file > Finish . After your preferences are imported now it is on to the projects.
To import your projects use the File > Import > Existing Projects into Workspace wizard. Here you will select the directories of your old projects and import them into your new workspace one at a time. With newer versions of Eclipse, there is a new option Copy Project into Workspace that is a good option to check before performing your Import. This will guaruntee that the physical files are copied out of the old workspace and into the new one. If you do not select this option, a link is created so you will need to keep the old workspace directory around as it holds the physical files (Thanks Sanjay for the pointer!) .
After you are done importing your projects, you are all set with a new and clean workspace, congratulations!
Clean Reinstall of Eclipse
Now let's say that none of the tips above worked, the problem you were having is still persisting and things just aren't working right. In my experience, if that is the case you most likely have a broken install which more times than not stems from using incompatible versions of plugins with the wrong base version of Eclipse. For example, trying to use a Eclipse 3.1 GA compatible plugin with Eclipse 3.2 Milestone 2 release. These plugin developers have guarantees from Eclipse of API stability during GA and stable release cycles that they develop against, when a stable plugin is then used in a nightly, integration or milestone build the chances that the underlying Eclipse APIs have changed are increased and it's possible that the plugin you are trying to use will no longer function correctly or just start functioning very strangely. As a responsible user you need to be aware of this and try and avoid this situation.
Now assuming you are using all the correct versions of Eclipse and your plugins and things are just broken (maybe you tested every plugin on EclipsePluginCentral and your install is shot) here's a good strategy for getting back to a clean install of Eclipse and your plugins.
First, I always suggest people perform new installs parallel to their old ones. Don't go erasing your old Eclipse install yet, use your new install for at least a week to make sure you got it right before you toast the old one. Be sure to write down or remember all the plugins you want to use with your clean install of Eclipse.
Second, redownload the most recent stable Eclipse release (Eclipse 3.1.1 is the current stable release at the time of this writing) and unzip it to a new location. Go ahead and install all of your plugins or at least the ones you can without running Eclipse.
Third, be sure to make all the necessary changes to your eclipse.ini file or shortcut for your new install that you had with your old install. Be sure to add the -clean command line argument for this first run since we are going to try and use your existing workspace for this initially.
Last, fire up your new install of Eclipse and point it at your existing workspace directory. Now play around and see if the install is working, if you are having a problem that continues to persist, the last step in this journey is to create a new workspace to use with your new install. Please follow the steps above in the Creating a new workspace section to do that.
If for some reason you are still experiencing trouble at this point, depending on the kind of problem, you should start looking at and testing native issues. Your operating system patch level, library versions, Java version, up to date drivers, memory checker, hard drive checker, virus checker, spyware checker, etc. Any time I've seen a problem go this far it usually turned out to be either a user fundamentally not understanding what they were doing and it was user error the entire time or there is a native issue as I outlined above at play here that needs to be resolved.
Conclusion
Now that you have made it this far, it means you have a clean Eclipse install. I hope this tip was helpful to some folks out there that might be having some "strange behaviors" and aren't quite sure why or what to do. Thank you for reading.