Tutorial: license headers in NetBeans

NetBeans has special support for the license headers we usually add at the begin of the source files for copyright messages and references to license agreement.

In the project properties we can find a dedicated section to license headers:

2014-02-18_pic01The “Use Global license” options let us choose among popular license header: Apache, GPL, MIT, NetBeans but in this tutorial we will create a custom license header.

First step is to create a file for our project license header. Let’s create a text file on the root of the project which will contain the text of the license header.



In this example, the file is named mylicense.txt and it is placed in the root of the project.

Now we open the mylicense.txt file to add some contents.


The text is free but it should formatted as a comment (in my case I used the Java block comment: /* */ ).

Important: actually the syntax of the license file can be more complex than in our example because it is processed by a tool during the inclusion process. I will post a new tutorial on this topic.

Save the file and close the editor window.

Now we return to the project properties window to specify the path of our project specific license header:


I used the variable ${project.basedir} which is the symbolic path to the project root dir. The window shows the preview of the license header.

Now, when we create a new file (in the example a new Java Class file), we have our template header in place:


For the moment, there is no option in NetBeans to add the template header to an already existing file but I filled an enhancement request on this.


7 thoughts on “Tutorial: license headers in NetBeans

  1. Pingback: Tutorial: license headers in NetBeans (reloaded) | Gualtiero Testa

  2. Pingback: tutorial-license-headers-in-netbeans-Junit-netbeans | mauroprogram's Blog

  3. I don’t know whether it’s just me or if everybody else experiencing problems with your blog.
    It looks like some of the text on your content
    are running off the screen. Can somebody else please
    provide feedback and let me know if this is happening to them as well?

    This may be a issue with my browser because I’ve had this
    happen previously. Cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s