• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eclipse removes unused imports

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
James Allen A.
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And it's important to leave 'Organize imports' from Window->Preferences->Java->Editor->Save Actions unchecked.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic