Automatically organize Java imports in Eclipse

This note relates to Eclipse SDK 3.6.2.

When editing a Java source file, in Eclipse, warnings are reported when an import statement is specified but not used. Unused import statements can be removed automatically by using the Java editor menu entry Source > Organize Imports.

This can be automatized when the file is saved using the following approach:

  1. Open “Preferences” page via menu Window > Preferences
  2. Navigate to Save Actions for Java Editor (Java > Editor > Save Actions)
  3. Select Perform the selected actions on save
  4. Select Organize imports
  5. Press button Apply

From this point on, when a Java file is saved, import statements will automatically be cleaned.

Leave a Reply

Your email address will not be published. Required fields are marked *