简体   繁体   中英

Can you organize imports for an entire project in eclipse with a keystroke?

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?

Select the project in the package explorer and press Ctrl + Shift + O (same keystroke as the single class version). Should work for packages, etc.

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.

This is how I keep my imports organized all of the time.

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 + O on the src folder.

如果要对整个项目运行保存操作,可以右键单击该项目,然后选择Source ,然后选择Clean Up ...

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 :

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 IDE:

  1. Select in your application, the package name, the one directly under the folder "src" in your project folder.
  2. Right click the package name and select "Organize Imports"
  3. Please don't forget to change the names too in the AndroidManifest.xml; otherwise, your app will crash.

For mac you can use Cmd + Shift + O . Alternatively, you can do it through the menu: 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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM