How to remove unused imports from Eclipse

前端 未结 10 1074
不思量自难忘°
不思量自难忘° 2020-12-12 10:57

Is there any way to automatically remove all unused imports (signaled with a warning) of a project with Eclipse IDE?

相关标签:
10条回答
  • 2020-12-12 11:18

    I just found the way. Right click on the desired package then Source -> Organize Imports.

    Shortcut keys:

    • Windows: Ctrl + Shift + O
    • Mac: Cmd + Shift + O
    0 讨论(0)
  • 2020-12-12 11:20

    If you want to do this on whole project then inside project -->select src folder-->press Ctrl+Shift+O

    0 讨论(0)
  • 2020-12-12 11:23

    You can direct use the shortcut by pressing Ctrl+Shift+O

    0 讨论(0)
  • 2020-12-12 11:36

    I know this is a very old thread. I found this way very helpful for me:

    1. Go to Window → Preferences → Java → Editor → Save Actions.
    2. Check the option "Perform the selected actions on save".
    3. Check the option "Organize imports".

    Now every time you save your classes, eclipse will take care of removing the unused imports.

    0 讨论(0)
  • 2020-12-12 11:37

    Remove all unused import in eclipse:

    Right click on the desired package then Source->Organize Imports. Or You can direct use the shortcut by pressing Ctrl+Shift+O

    Work perfectly.

    0 讨论(0)
  • 2020-12-12 11:37

    Better way is just to add "save action" so when you save the project it will clear the unused import's and format the code as well if you like .

    Go to Window > Preferences > Java > Editor > Save Actions

    and pick what ever you want .

    0 讨论(0)
提交回复
热议问题