Custom Code Templates in Eclipse IDE


If you are using the Eclipse IDE you can speed up your development time by using the code template feature. Per default code templates are accessible by cycling through the code assist (CTRL + Space) directly from the source code editor. Each code template have one or many keywords assigned, e.g. if you’re applying code templates onto the keyword sysout Eclipse replaces the keyword with System.out.println().

Feel free to inspect the whole list of code templates from Preferences -> Java -> Editor -> Templates. It’s up to you to add your own code templates for your common programming tasks. One of my personal code templates is assigned to the keyword logger. It declarates an Apache Commons Logging member on class level. The code template looks like this:

private final Log logger = LogFactory.getLog(getClass());
${log:import(org.apache.commons.logging.Log)}
${logfactory:import(org.apache.commons.logging.LogFactory)}

Read More