NetBeans Custom Project License |
 |
 |
 |
|
Written by Alex Balyuk
|
|
Sunday, 15 August 2010 16:06 |
|
Ever wondered how most professionally done projects have nice license block at the top of every source file?
This block is more important than you think. I provides a lot of useful information about the file, where it came from, when, why, and who... This information is very useful and will help you and other developers to understand reasoning behind the file's existence. It would be very annoying to copy and paste license block into every file and modify timestamps for @id property every time you edit the file. This block is generated automatically by an IDE such as NetBeans , here is how it is done...
- Create new empty txt document somewhere on your computer. You can delete this file after Step 5. Name must be in following format license-YourLicenseName.txt
license-boolcast.txt
- Run NetBeans IDE and open Template Manager (Tools -> Templates)

- Select/Highlight Licenses node

- Click "Add..." button on the right
- In the Open File Dialog find the file created in Step 1 and click "Add". Now you will see this file under Licenses node
- Highlight your license file and click "Open in Editor" button

- Edit the file to your liking/requirements. Save it and close.
My license block looks like this:
/**
* @version $Id$
* @package BoolCast
* @copyright Copyright (C) 2010
* @license Proprietary
*/
- Open the Project that will be using this license. I will be using PHP project
- Open Files window (usually next to Projects). If you do not see Files window, go to Window->Files
- Extend nbproject directory and open project.properties
- Add new property called project.license and set it to the name of your license file without "license-" prefix
project.license=boolcast

- Save and Close
Congratulations! You are done. Now every file you create will have your custom license block.
Create a new file, just to double check. New file will look something like this:

Couple of things to note:
- Once you add the license file to the NetBeans templates the file is copied to the NetBeans Templates directory. On Linux and Windows the path is pretty much the same
/User Home/current netbeans directory/config/Templates/Licenses
In current example the path is
C:\Users\Alex\.netbeans\6.9\config\Templates\Licenses
- The "Duplicate License" button does not work properly and error reading file was displayed instead of license block. This was happening because after duplicating the license license name is not what you named it. For example, lets say you duplicated "license-default" to "license-MyLicense", the file name will be named "license-default_1" and not "license-MyLicense". Workaround is to create an empty file and add it and then edit it, this way name will be preserved
Error reading included file Templates/Scripting/../Licenses/license-YourLicenseName.txt
- $Id$ requires version control property
|
|
Last Updated on Monday, 06 September 2010 20:04 |