Ruben Laguna's blog

Mar 5, 2009 - 3 minute read - Comments - freemarker gpl gplv3 license netbeans template variables

GPLv3 license template for Netbeans

To add an GPL notice to all your new files

Just open the Netbeans Template Manager by clicking Tools ⇒ Templates.

Click on the Default License and press the Duplicate button. Then select the newly created “license-default_1.txt” and rename it to “license-gplv3.txt” (the name it’s important copy exactly the same name). Then click on “Open in Editor” button and replace the contents of the license file with the following:

< #if licenseFirst??>
${licenseFirst}

${licensePrefix}${nameAndExt}
${licensePrefix}
${licensePrefix}Copyright (c) ${date?date?string("yyyy")} ${user}.
${licensePrefix}
${licensePrefix}This file is part of ${program}.
${licensePrefix}
${licensePrefix}${program} is free software: you can redistribute it and/or modify
${licensePrefix}it under the terms of the GNU General Public License as published by
${licensePrefix}the Free Software Foundation, either version 3 of the License, or
${licensePrefix}(at your option) any later version.
${licensePrefix}
${licensePrefix}${program} is distributed in the hope that it will be useful,
${licensePrefix}but WITHOUT ANY WARRANTY; without even the implied warranty of
${licensePrefix}MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
${licensePrefix}GNU General Public License for more details.
${licensePrefix}
${licensePrefix}You should have received a copy of the GNU General Public License
${licensePrefix}along with ${program}.  If not, see <http ://www.gnu.org/licenses/>.
< #if licenseLast??>
${licenseLast}

Make sure that the template has been properly renamed in the filesystem. You should have a ~/.netbeans/6.7/config/Templates/Licenses/license-gplv3.txt file. If not you may have to manually rename the file.

This template that you just created makes use of two user variables (user and program) that you have to define in Netbeans Template Manager ⇒ User Configuration Properties ⇒ User.properties

the User.properties should look like

#
# 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=Ruben Laguna <ruben .laguna at gmail.com>
program=XBeeApplication

As Michal Hlavac has pointed out in the comments you could use ${project.displayName} instead of ${program}. This variable is automatically set by netbeans. So you don’t need to edit User.properties every time you switch projects But I should point out that I tried it with Netbeans Platform Application project and it doesn’t work for me and I even reported it to Netbeans Issuezilla.

Then the next step is to define that you want to use GPLv3 for your project. Just add the following line to you project.properties file

project.license=gplv3

Now just select New ⇒ Java Class to create a new class and you’ll get the GPLv3 license at the top of the file with the proper copyright line and customized to your application name.

/*
* NewClass.java
*
* Copyright © 2009 Ruben Laguna <ruben.laguna at gmail.com>.
*
* This file is part of XBeeApplication.
*
* XBeeApplication is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XBeeApplication is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBeeApplication. If not, see <http ://www.gnu.org/licenses/>.
*/

References:

Setting XBee to sleep causes Arduino reset Arduino popularity is on the rise