Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top