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

JavaEclipseKeyboard Shortcuts

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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.

Solution 3 - Java

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.

Solution 4 - Java

If you want to run save actions against a whole project you can right click on the project, then choose Source and then Clean Up...

Solution 5 - Java

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 I.D.E.:

  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.

Solution 6 - Java

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. :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbranchgabrielView Question on Stackoverflow
Solution 1 - JavaToddView Answer on Stackoverflow
Solution 2 - JavajjnguyView Answer on Stackoverflow
Solution 3 - JavasosFreelancerView Answer on Stackoverflow
Solution 4 - Javameh-ukView Answer on Stackoverflow
Solution 5 - JavasuperlinuxView Answer on Stackoverflow
Solution 6 - JavaJames OravecView Answer on Stackoverflow