Loading

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
< #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

1
2
3
4
5
6
7
8
9
10
#
# 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
</ruben>

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 (c) 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/>.
 */
 
</ruben>

References:

4 Comments

  1. Posted June 13, 2009 at 6:03 pm | Permalink

    IMO most common way for more than one project is use variable ${project.displayName} instead of ${program}. This variable is automatically set by netbeans. So you needn’t edit User.properties every time you switch project.

  2. Ádám
    Posted June 14, 2009 at 10:10 am | Permalink

    Wow, this was really helpful! Thanks Ruben and Michal!

  3. Posted July 25, 2009 at 5:14 pm | Permalink

    I tried to use the ${project.displayName} variables for Netbeans Platform Application project and it didn’t work for me. (for regular Java applications projects seem to work ok)

  4. Anonymous
    Posted January 9, 2010 at 12:32 pm | Permalink

    Hi,
    You’ve got “All rights reserved.” in the template. Please remove that, since that is not what is supposed to come with GPL. Unless you meant “All rights reversed” (reversing the s and v to get reverse).

One Trackback

  1. [...] was trying to use these variables as pointed out by Michal Hlavac in my post about templates. And then I realized that these variables don’t seem to work for Netbeans Plaform Application [...]

Post a Comment

Your email is never shared.