Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 340
usr Avatar asked Nov 21 '09 12:11

usr


People also ask

How do I delete unnecessary imports in Eclipse?

Eclipse provide a shortcut CTRL + SHIFT + O, this shortcut command will remove all those unused imports from your code file.

How do I organize imports in Eclipse project?

Here are the steps to organising imports whenever you save: Go to Window > Preferences > Java > Editor > Save Actions. Select Perform the selected actions on save (off by default). Ensure that Organize imports is selected (on by default).

How do I get rid of unwanted imports?

1) Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and one of them will be "remove unused imports." It will remove that import statement from Java file.

How do I manage imports in Eclipse?

It's better to use the “Organize Imports” feature of Eclipse IDE to remove multiple or all unused imports statement. For using this from Menu, Select Source → Organize Imports. This will remove all unused imports from that Java file.


2 Answers

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

like image 95
Mirek Pluta Avatar answered Oct 13 '22 11:10

Mirek Pluta


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.

like image 22
Mainguy Avatar answered Oct 13 '22 13:10

Mainguy