aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse removes unused imports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse removes unused imports" Watch "Eclipse removes unused imports" New topic

Eclipse removes unused imports

James Allen A.

Joined: Mar 10, 2013
Posts: 24
I found other related threads but none that specifically address removed unused imports. I added several unused imports that I would like to later use. After saving and compiling my project, I find that some that are used are consolidated to one line, while others that aren't used are removed completely. Can I tell eclipse to never remove imports?
Paul Clapham

Joined: Oct 14, 2005
Posts: 18115

As far as I'm aware Eclipse doesn't do anything with imports unless you specifically tell it to do so (by pressing Ctrl-O, I think, or some similar key sequence). But I could be wrong... can you replicate a sequence of events in which Eclipse cleans up your imports without you specifically telling it to do that?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990

Ctrl+O is for quick outline.
Ctrl+Shift+O will organize the imports (and remove unused ones as per your settings)
I am not running a vanilla flavor of Eclipse right now. Look for organize imports and code formatting options under Eclipse preferences

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
James Allen A.

Joined: Mar 10, 2013
Posts: 24
I see. I must have tried CTRL + O before I verified they were removed. They were probably minimized then I inadvertently removed them. I just tried to reproduce my problem and couldn't do it so all is well. Thanks!
Zmicer Szybieka

Joined: Jun 28, 2013
Posts: 2
Eclipse removes unused imports when you click save if it's configured this way in
Window->Preferences->Editor->Save Actions.
There is a list of additional actions, which you might want to configure.
Zmicer Szybieka

Joined: Jun 28, 2013
Posts: 2
And it's important to leave 'Organize imports' from Window->Preferences->Java->Editor->Save Actions unchecked.
I agree. Here's the link:
subject: Eclipse removes unused imports
Similar Threads
Coding Standards
Eclipse Ganymede + GWT plugins extremly slow HELP
How to find unused imports and remove unused imports.
Compile time inport & run time import