As a general rule I don’t include license information at the top of each source file (I’m sure a lawyer would be outraged) because no one but me should ever see the source. I’ve recently started work on an open source project though so I thought I’d best investigate how to get NetBeans to automatically include some Apache 2.0 license blurb at the top of each source file.
All my projects use Maven so when I turned up this page on defining a project license my heart sank a little. I really couldn’t be bothered to add the license manually each time. Fortunately I quickly discovered that NetBeans has pretty good support for licenses specified in the Maven pom.xml file.
The first thing to do is include a licenses block in your pom file. This is used when building the site to display the license text:
<licenses> <license> <name>Apache 2</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>repo</distribution> <comments>A business-friendly OSS license</comments> </license> </licenses>
Additionally you will want to include a NetBeans hint property to tell it to include the appropriate header text:
<properties> <netbeans.hint.license>apache20</netbeans.hint.license> </properties>
The name that you specify for the license has to be one defined under Tools > Templates > Licenses. Remove the extension and the license- prefix.
References
- Details of NetBeans Maven properties.
- Details of the license element in pol files.
- NetBeans Maven best practices.
- Discussion on adding license information.