How to bulk cleanup imports in Java with Eclipse? [duplicate]
Asked Answered
S

4

10

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?

Salisbury answered 21/11, 2009 at 12:21 Comment(0)
P
33

In package explorer right click on the root package of your project and choose source -> organize imports

Paediatrics answered 21/11, 2009 at 12:22 Comment(1)
Or select the classes and or packages you want to fix in the package explorer and organise their imports like described.Closehauled
M
2

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.

Marshmallow answered 21/11, 2009 at 12:41 Comment(1)
Just tried it with the project selected in the Package Explorer and it worked (I'm using Kepler) .Dealings
C
2

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..

Cushat answered 12/9, 2012 at 12:7 Comment(0)
C
1

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.

Confirm answered 21/11, 2009 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.