How to Modify the Default NetBeans Template

By default every single class that you create with NetBeans will start with a header that tells you how to change the template. This header has found it’s way into just about every file in all my projects and it serves no useful purpose, why it can’t just be an empty comment I don’t know but this document describes how to change it.

The offending blurb at the top of a new class is this:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

What I would like is either nothing, an empty comment or perhaps a simple copyright notice.

The problem, really, is that the message isn’t very clear. Yes, you change the blurb by opening the templage in Tools > Templates but the template you need to modify isn’t any one under Java it’s the default licence template that contains the text. The default licence template looks like this:

<#if licenseFirst??>
${licenseFirst}
</#if>
${licensePrefix}To change this template, choose Tools | Templates
${licensePrefix}and open the template in the editor.
<#if licenseLast??>
${licenseLast}
</#if>

What you probably want is something more like this:

<#if licenseFirst??>
${licenseFirst}
</#if>
${licensePrefix}Copyright ${date?date?string("yyyy")} Company Name
<#if licenseLast??>
${licenseLast}
</#if>

Which simply adds a copyright notice and the name of the company you are currently selling your soul to 😉

Update

While you are in there modifying templates you probably also want to modify the name that the IDE inserts for you as author as it never seems to get it right. From the menu select Tools > Templates and click the Settings button. This will open a properties file into which you can add the property “user=Your Name”. Now NetBeans will get your name right all the time.