NetBeans 6 comes with a brand new functionality for including project-based licenses in source files. This enables you to easily use different licenses in the headers depending on the project you are working on.
Using the functionality is simple, here are the steps:
- Add your licenses to the NetBeans templates
- Update the
project.properties
to specify the desired license
Okay, first we add a license to the NetBeans template. For the sake of this example I'll add the GPL license:
- Click Tools -> Templates
- Expand the "Licenses" folder
- Select "Default License"
- Click the "Duplicate" button (a new template is created called license-default_1.txt)
- Select license-default_1.txt
- Click the "Rename" button
- Name the new license license-gpl.txt (notice, the name should follow the format: license-
.txt) - Select license-gpl.txt
- Click "Open in Editor"
- Enter the following text (GPL license) into the editor:
<#if licenseFirst??>
${licenseFirst}
</#if>
${licensePrefix}${name}.java
${licensePrefix}
${licensePrefix}Copyright (C) ${date?date?string("yyyy")} Allan Lykke Christensen
${licensePrefix}
${licensePrefix}This 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 this program. If not, see <http://www.gnu.org/licenses/>.
<#if licenseLast??>
${licenseLast}
</#if> - Replace the author name
- Save and close the template (CTRL+S followed by CTRL+W)
You have successfully added the template to NetBeans for use in future projects.
To use the license in a project do the following:
- Open the "Files" view (CTRL+2)
- Expand the
nbproject
folder of your project - Open the
project.properties
file - Add
project.license=gpl
in the end of the file, or if you already have a line startingproject.license
replace it. - Save and close the file
Alright, you are ready to try out the license. Create a new Java class in your Source Packages and viola, the source file is using the newly created license.
In a future version of NetBeans I expect that it will be possible to select the license from the project properties page rather than you having to tinker around with
project.properties
.
6 comments:
Allan,
Sorry it does not work for me. After a first mistake (I typed licence instead of license) I did all the steps, and I verified several times : all is now OK in the configuration files.
But it is still the default license when I create a new Java Class...
Any idea?
Thanks in advance.
Olivier
Hi Olivier,
Hm, sounds strange. I think you might have a difference in spelling in the license template and the license identifier in project.properties.
Ensure that in the templates the license it called license-YOUR_ID.txt and in project.properties you have a corresponding line:
project.license=YOUR_ID
If you still have problems feel free to e-mail me and I'll see what I can do to help.
Kind regards,
Allan
Dear Allan,
The method succeeds for me but then i have a "resolve reference problem" : netbeans wants me to provide a "license" project. Do you know this issue? It is Netbeans 6.0.1
Thanks.
Regards,
Cyril.
Hi Cyril,
It sounds like you might have accidentally added a line containing reference=license or similar. Does the reference problem disappear when you remove the line from project.properties?
Kind regards,
Allan
It appears this works fine for regular Java projects but not for Enterprise Application projects.
It also works for Enterprise applications, but you will have to add it to each of the EJB and WAR projects that is part of the Enterprise application and not just the project.properties for the Enterprise application.
Post a Comment