Learn how to customize the author tag value with the template manager of NetBeans.

Usually, when you work either with Java or PHP in NetBeans, automatic created classes will include the @author documentation in the comments of the class, for example, if there's no user configured on NetBeans to change this content, the class will look like:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sandbox;

/**
 *
 * @author sdkca
 */
public class Sandbox {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

As you can see, normally NetBeans will take either the username of the computer or will simply don't add the @author tag to the documentation. You can change the default text that is set by NetBeans during the creation of such files automatically using custom templates. In this article, we'll explain you how to configure this easily in NetBeans 8.2.

1. Open NetBeans Template Manager

To open the template manager of NetBeans, access the Tools button on the top bar menu and click on the Templates option:

NetBeans Template Manager

After clicking on Templates, a new window will appear, namely the Template Manager Window. Once this window appears, click on Settings:

NetBeans Template Manager Settings

2. Modify User.properties file

After clicking on Settings from the previous dialog, NetBeans will open the User.properties file of the IDE in a new tab. By default this file contains the following text:

#
# Here, or in other properties files in this directory, you can define
# various properties that you want to make available to the template
# processor while creating various templates.
#
 
# uncomment the next line and specify your user name to be used in new templates
# user=Your Name <your.name at your.org>

The property for the author, is the user, so define as value the text that you want to appear on the new classes or code templates that include this variable. For example, we'll modify our value with the next value:

#
# Here, or in other properties files in this directory, you can define
# various properties that you want to make available to the template
# processor while creating various templates.
#

# uncomment the next line and specify your user name to be used in new templates
user=Carlos Delgado <[email protected]>

After saving changes on the file, if you proceed to create a new file that uses this value, you will find the new author text:

NetBeans Author Variable

Happy coding !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors