This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse removes unused imports" Watch "Eclipse removes unused imports" New topic
Author

Eclipse removes unused imports

James Allen A.
Greenhorn

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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: 10172
    
    8

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

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
Greenhorn

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: Eclipse removes unused imports
 
Similar Threads
Eclipse Ganymede + GWT plugins extremly slow HELP
Compile time inport & run time import
How to find unused imports and remove unused imports.
Coding Standards
imports