How to bulk cleanup imports in Java with Eclipse? [duplicate]
On a generated project I get 100s of warnings caused by unused imports and such things. Can I bulk cleanup those imports for all files?
In package explorer right click on the root package of your project and choose source -> organize imports
CTRL-SHIFT-O will do this on a file by file basis in eclipse, if you want to do an entire project, you might need to use something like jalopy. There is a jalopy eclipse plugin, but I'm not sure if it will do an entire project at one time or not.
Please consider all pros and cons of bulk import before doing it. Its helps you to organise imports, but somtimes it make work more tedious by not organizing imports for same class namein different package. Suppose you have class A in two different packages, bulk import will struggle to import and you need to revist again to this manually.
Consider turning on organize imports for Save Actions in preferences..
After you have gotten rid of your import warnings, consider turning on Save Actions for Java Editors in preferences. We do the suggested source cleaning, plus we format the source. Makes it much easier to see exactly when a change was introduced later.
精彩评论