Eclipse Tip: Add imports with Code Templates

Code templates have been in Eclipse for a long time. I have blogged about it a long time ago. I have been using it for inserting commonly used statements like logging statements…

When I am inserting a logger declaration I always end up with this:

Eclipse does not know which logger to import. In my case I want it to import the apache logger. Now there is a way you can tell Eclipse to import this automatically. Just edit the code template and add the following:


This is cool and saves a bit of time. :-) For more information on template variables look here.

2 thoughts on “Eclipse Tip: Add imports with Code Templates”

  1. Hi Vasanth,

    Do I need some aditional steps? Like restart, a particular version? Because I already have a getlogger template without the import enhacement and still needs to organize the imports after the template call.

    This is the template code:
    private final static Logger logger = Logger.getLogger( ${enclosing_type}.class );

    I am currently using Eclipse SDK 3.3

Comments are closed.