Automating imports in Eclipse

G’day all,

Just a quick and silly question about Eclipse. Is it possible to set a standard list of imports that will appear in my projects? I guess a ‘template’ is the word I’m looking for. If so, where do I start looking?

Reason being, I always seem to be copying and pasting the same old imports in to my projects. Would be handy if Eclipse did it for me, and I’m sure someone has thought of this well before I have.

Cheers,
nerb.

Better yet: Save Actions

In Window > Preferences > Java > Editor

Select “Organize Imports”
Customize settings by clicking the link.

One effect of this is that, on save, eclipse will add imports for things that you are using, so just write the code (will highlight as a error), then ctrl-s and the imports automatically appear. Never write an import statement again!

Also, turn on the auto-formatter, it’s pretty nice with the right settings.

Eclipse: Ctrl + Shift + O

never write imports again.

Or set to do it on-save, so that turns into Ctrl-S, which most probably press quite habitually anyway.

Brilliant. Thankyou both. I use a lot of static imports, which didn’t seem to initially mesh with either method, but have since found some options in the Preferences menu which should sort it out. I’ll play around and see how I go.

Cheers muchly.