November 26, 2008

Code templates speed up writing POM files in NetBeans

NetBeans provides several code templates for different languages. One of the "languages" is the Maven pom.xml file. We can see the different templates if we go to Tools | Options | Editor | Code Templates, there we select Apache Maven POM files from the Language select box. NetBeans shows the different templates in the Templates table. The abbreviation column shows what we need to type and the Expand Template on select box shows which key is used to expand the abbreviation to a complete template.

Let's go to a pom.xml file and in the dependencies element we type dep. In the screenshot we see that we typed dep at line 12.

Next we press the Tab key. NetBeans expands dep to a complete dependency element and the cursor is placed at the groupId element so we can go right ahead and fill in the correct value.

After we have typed in a value for the groupId element we can type the Tab key again and the cursor is placed in the artifactId element. So NetBeans jumps right to the place we need to fill in values for the code template! This way we can achieve a lot with only a few keystrokes.