Java 您可以在 Eclipse 中通过按键组织整个项目的导入吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/403569/
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
Can you organize imports for an entire project in eclipse with a keystroke?
提问by branchgabriel
Wouldn't it be nice to just do a keystroke and have eclipse organize all imports in all java classes instead of just the one you are looking at? Is this possible? Is there a keystroke for it?
只需按一下键并让 Eclipse 组织所有 Java 类中的所有导入,而不仅仅是您正在查看的类,这不是很好吗?这可能吗?有按键吗?
采纳答案by Todd
Select the project in the package explorer and press Ctrl+ Shift+ O(same keystroke as the single class version). Should work for packages, etc.
在包资源管理器中选择项目并按Ctrl+ Shift+ O(与单类版本相同的按键)。应该适用于包等。
回答by jjnguy
You can edit the clean up options on save to make it organize imports. That way all of your imports will always be organized.
您可以在保存时编辑清理选项以组织导入。这样,您的所有导入都将始终得到组织。
In eclipse 3.4 just go into Window - Preferences. In the tree view look under Java -- Editor -- Save Actions.
在 Eclipse 3.4 中,只需进入 Window - Preferences。在树视图中查看 Java -- Editor -- Save Actions。
This is how I keep my imports organized all of the time.
这就是我一直保持我的进口组织的方式。
回答by sosFreelancer
For Eclipse Helios, open the "Project Explorer" view, clic right on your src folder, go under the source menu, and clic "organize imports" that should work for all your project. or just hit the combination Ctrl+ Shift+ Oon the src folder.
对于 Eclipse Helios,打开“项目资源管理器”视图,单击 src 文件夹,进入源菜单,然后单击应该适用于所有项目的“组织导入”。或者只是点击src 文件夹上的组合Ctrl+ Shift+ O。
回答by meh-uk
If you want to run save actions against a whole project you can right click on the project, then choose Sourceand then Clean Up...
如果你想运行保存对整体项目,你可以右键点击该项目的操作,然后选择源,然后清理...
回答by superlinux
I have Leadbolt ads in my Android app. On every Leadbolt version, Leadbolt force me to re-update the name of the java import. For example, in my app it was :
我的 Android 应用中有 Leadbolt 广告。在每个 Leadbolt 版本上,Leadbolt 强制我重新更新 java 导入的名称。例如,在我的应用程序中它是:
import com.kwswsuyruzouggmtbzxb.*
Then on the update they gave me a new package with the name:
然后在更新时,他们给了我一个名为的新包:
import com.izwevyqazy.*
And therefore, I have to make a change from the older name to the newer name on around 20 or more of java source code files. So, what I did is to re-organize the imports using this way in Eclipse I.D.E.:
因此,我必须将大约 20 个或更多 Java 源代码文件的旧名称更改为新名称。所以,我所做的是在 Eclipse IDE 中使用这种方式重新组织导入:
- Select in your application, the package name, the one directly under the folder "src" in your project folder.
- Right click the package name and select "Organize Imports"
- Please don't forget to change the names too in the AndroidManifest.xml; otherwise, your app will crash.
- 在您的应用程序中选择包名称,即项目文件夹中“src”文件夹下的名称。
- 右键单击包名称并选择“组织导入”
- 请不要忘记更改 AndroidManifest.xml 中的名称;否则,您的应用程序将崩溃。
回答by James Oravec
For mac you can use Cmd+ Shift+ O. Alternatively, you can do it through the menu: Source -> Optimize Imports
对于 Mac,您可以使用Cmd+ Shift+ O。或者,您可以通过菜单进行操作:Source -> Optimize Imports
You can run this on individual files, or for each source folder. The option is greyed out if you try it at the project level of the project explorer. So you may have to do it a couple time if you have a bunch of modules and source folders. :)
您可以对单个文件或每个源文件夹运行此操作。如果您在项目资源管理器的项目级别尝试该选项,则该选项会变灰。所以如果你有一堆模块和源文件夹,你可能需要做几次。:)