For our open source project jcompare we are using MIT license. According to the open source tradition we wanted the MIT license to be included in our source code files. NetBeans makes the inclusion of license piece of cake through the templates feature.
We will use the Tools Menu and Templates option
In the various categories we have to select the Licenses Node. We need MIT license to be listed there. Initially there are only two entries under the Licenses node. NetBeans CDDL and Default License. The best way to create another license is select existing license and press the Duplicate button.
Let us press the duplicate button and we get a new License entry. Important thing to note here is the license name shall be exactly as license-MIT.txt
This will ensure we can use the default Java Class template as it is. Now we will select that entry license-MIT.txt and press the Open in folder button to open this file. We will have to change this file with our
MIT license text which we will get from
OSI site.
<#if licenseFirst??>
${licenseFirst}
${licensePrefix}Copyright (c)
${licensePrefix}
${licensePrefix}Permission is hereby granted, free of charge, to any person obtaining a copy
${licensePrefix}of this software and associated documentation files (the "Software"), to deal
${licensePrefix}in the Software without restriction, including without limitation the rights
${licensePrefix}to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
${licensePrefix}copies of the Software, and to permit persons to whom the Software is
${licensePrefix}furnished to do so, subject to the following conditions:
${licensePrefix}
${licensePrefix}The above copyright notice and this permission notice shall be included in
${licensePrefix}all copies or substantial portions of the Software.
${licensePrefix}
${licensePrefix}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
${licensePrefix}IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
${licensePrefix}FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
${licensePrefix}AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
${licensePrefix}LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
${licensePrefix}OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
${licensePrefix}THE SOFTWARE.
<#if licenseLast??>
${licenseLast}
Next step we will follow is to open the project.properties file. We will navigate to the Files panel and expand the nbproject folder to see this file and double click on it to open it in editor.
We will add a new property in this file at the end.
That property will be
project.license=MIT
Now when we create a new class in our project the license text will be included as required.
The license file gets created in the config\Templates folder of the NetBeans user directory as shown in the image below:
with regards
Tushar Joshi, Nagpur
References: