Organizing your Imports using Eclipse

Posted Tue, 24 Jun 2008

Just a quick follow up to my last post - a very quick way to organize all your imports across all your source, assuming you use Eclipse (or an Eclipse based) IDE.

In your Project Explorer panel, highligh each of your Java source files. Then right click, and choose Source->Organize Imports, like so:

This will not only replace any wild-card imports with only those you explicitly need, it will also sort them out by package name.

You do have some control over this process - to set your workspace settings for organizing imports, select "Preferences" from the "Window" menu:

Here, you can define the sort order, and upper thresholds for how many explicit imports are too many. On mine, it's set to 99; which is for all intent and purposes "always use explicit includes". If you use 99 classes from any one package in a single source file, you have bigger fish to fry.

Related Books

Eclipse Web Tools Platform: Developing Java(TM) Web Applications Effective Java (2nd Edition) (Java Series) Head First Java, 2nd Edition Eclipse Rich Client Platform: Designing, Coding, and Packaging Java(TM) Applications (Eclipse Series) Eclipse: Building Commercial-Quality Plug-ins (2nd Edition) (Eclipse Series)

Post a Comment




About

My name is Tim Fanelli, I am a software engineer in Northern NY. I spend most of my time working, and when I can, I try to post interesting things here.

Cigar Dossiers