Remove unused import from All projects in eclipse
Asked Answered
L

5

16

Is there a way , a shortcut or any setting which removes unused import from all projects ? effectively from workspace?

I found following question which states about removing from single file. How to remove unused imports from Eclipse.

But I need from whole workspace?

P.S.: Let me know if there are in any case ,a plug ins available for performing same.

Leonleona answered 8/1, 2013 at 13:23 Comment(3)
Dont u hv ever use project explorer and then select the project and go to source and it has an option organize import ctr+shift+o ?Teferi
Also remember that you can add this as an save action. Then this will be performed everytime you save a file. Search for "save action" in preferences.Sensible
@Sensible : yeah I am already using it as a save action.Leonleona
M
58

Key combination Ctrl+ Shift + O - will trigger the Organize Imports that will remove and add missing imports.

To apply it on whole workspace you just have to select the project in the view Package Explorer and then use the key combination

Medallist answered 8/1, 2013 at 13:27 Comment(6)
It is for single file only.Leonleona
It can be applied to entire projects too, or you can right click on a project and select it from the 'Source' menu.Everetteeverglade
@PriyankDoshi, This works on selected item view. If it is editor then it is single class if it is Package Explorer then it work on selected items.Oraleeoralia
Nice answer, thanks.it worked in Java perspective. but, not in Java EE perspective :(Epilogue
@Keerthivasan: yes. But in Java EE, it is Project Explorer not Package Explorer :)Haily
Actually only works for me when selecting all packages within project. Selecting project itself does not work, ecl oxygenXiaoximena
T
6

Right click your working set node, or all projects that you need and select Source->Organize Imports.

Shortcut is Ctrl+Shift+O, it is basically written in the menu so if you are using a different OS, you should be able to find it. It works on single files as well as project nodes in the Package Explorer

Thora answered 8/1, 2013 at 13:26 Comment(0)
H
6

As said, Ctrl+ Shift + O to do it manually or Window -> Preferences -> Java -> Editor -> Save Actions -> Organize Imports to have it organized automatically whenever you save a class.

Hysteresis answered 8/1, 2013 at 19:37 Comment(1)
in MAC, its Eclipse -> PreferencesCelluloid
O
1

Eclipse Workspace -> Java Resources -> right click on (src/main/java) folder -> Select Sorce from the menu -> Now finally select Organize import & you are done.

Ode answered 9/9, 2019 at 11:1 Comment(0)
F
0

For macOS , you can use -->control+option+O combination.

Farceuse answered 16/6, 2022 at 17:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.