Netbeans source files license header by project

In case you’ve never found this Geertjan’s post Project-Level License Settings in NetBeans IDE 6.0. There is some extreamly useful project specific license feature in Netbeans that really makes life easier when you swap projects often, and each is made for different customer with different license. Here’s what you have to do to make Netbeans fill source files header for you:

First, go to Tools/Templates and add new License template:

What’s strange is that when you click add, you have to select some text file. It will be copied to Netbeans configuration directory. Let’s make it an empty text file. It has to be named license-*.txt. What you put in place of * will be the license name.

Then click Open in editor and type your license header content:

<#if licenseFirst??>
${licenseFirst}
<!--#if-->
${licensePrefix}Copyright (C) ${date?date?string("yyyy")} Bond, James Bond
${licensePrefix}
${licensePrefix}This is for your eyes only!
${licensePrefix}Destroy after reading!
<#if licenseLast??>
${licenseLast}
<!--#if-->

${licenseFirst}, ${licensePrefix} and ${licenseLast} will be substituted with comment characters of language current file is in (/* * */ – in C++/Java).
${date?date?string("yyyy")} will be changed to actual year.

You can find some more examples in other license templates you’ve got from Netbeans team on install. Just open them in editor.

Then let’s configure our project to use this new license:
What you need to do is edit nbproject/project.properties file and add line like:
project.license=Bond
and reopen the project and you’re done. Netbeans will automatically include your license header in every new file you create. Here’s what I’ve got:

Java source:

/*
 * Copyright (C) 2011 Bond, James Bond
 *
 * This is for your eyes only!
 * Destroy after reading!
 */
package bondproject;

public class James {

}


Properties file:

# Copyright (C) 2011 Bond, James Bond
#
# This is for your eyes only!
# Destroy after reading!

name=James
gender=Male


…and so on.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: