从 eclipse 中的所有项目中删除未使用的导入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14215936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:46:19  来源:igfitidea点击:

Remove unused import from All projects in eclipse

javaeclipseimportrefactoring

提问by Priyank Doshi

Is there a way , a shortcut or any setting which removes unused import from all projects? effectively from workspace?

有没有办法、快捷方式或任何设置可以从所有项目中删除未使用的导入?有效地从工作区?

I found following question which states about removing from single file. How to remove unused imports from Eclipse.

我发现以下问题说明了从单个文件中删除。如何从 Eclipse 中删除未使用的导入

But I need from whole workspace?

但我需要从整个工作区?

P.S.: Let me know if there are in any case ,a plug ins available for performing same.

PS:让我知道在任何情况下是否有可用于执行相同操作的插件。

回答by Damian Leszczyński - Vash

Key combination Ctrl+ Shift + O- will trigger the Organize Importsthat will remove and add missing imports.

组合键Ctrl+ Shift + O- 将触发Organize Imports将删除和添加丢失的导入。

To apply it on whole workspace you just have to select the project in the view Package Explorerand then use the key combination

要将其应用于整个工作区,您只需在视图中选择项目Package Explorer,然后使用组合键

回答by Waqas Ilyas

Right click your working set node, or all projects that you need and select Source->Organize Imports.

右键单击您的工作集节点或您需要的所有项目,然后选择 Source->Organize Imports。

Shortcut is Ctrl+Shift+O, it is basically written in the menu so if you are using a different OS, you should be able to find it. It works on single files as well as project nodes in the Package Explorer

快捷键是Ctrl+Shift+O,它基本上写在菜单中,所以如果你使用不同的操作系统,你应该可以找到它。它适用于包资源管理器中的单个文件以及项目节点

回答by Marcel St?r

As said, Ctrl+ Shift + Oto do it manually or Window -> Preferences -> Java -> Editor -> Save Actions -> Organize Imports to have it organized automatically whenever you save a class.

如前所述,Ctrl+ Shift + O要手动执行或 Window -> Preferences -> Java -> Editor -> Save Actions -> Organize Imports 以在保存类时自动组织它。

回答by SHUBHAM RUHELA

Eclipse Workspace -> Java Resources -> right click on (src/main/java) folder -> Select Sorce from the menu -> Now finally select Organize import & you are done.

Eclipse 工作区 -> Java 资源 -> 右键单击​​ (src/main/java) 文件夹 -> 从菜单中选择 Sorce -> 现在最后选择 Organize import,你就完成了。