How do I create and use a Java template?
Author: Deron Eriksson
Description: This tutorial describes how to create and use a Java template in Eclipse.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)


Page: < 1 2

(Continued from page 1)

Now, let's try out the 'log' JavaSW template. To do so, I type 'log' in my Java file and then hit Control-Space to activate code-completion. I double-click the 'log' template.

Utilizing Java Template via code completion

This automatically inserts the template code into my Java file, as shown.

Java Template inserted into code

Let's finish things by resolving the import. I hit Control-Shift-O to 'organize imports'. There are two Logger classes in the build path, so I select the desired one, org.apache.log4j.Logger.

Organize Imports

Our import for the Logger has been created. I save the file.

Logger imported

Java templates can be a great time-saver. As you can see, in a couple clicks, you can automatically insert useful code into your Java files.

Page: < 1 2