DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Personalized Code Templates in NetBeans 7.0

Personalized Code Templates in NetBeans 7.0

Bruce Schubert user avatar by
Bruce Schubert
·
Apr. 29, 11 · Java Zone · Interview
Like (1)
Save
Tweet
29.78K Views

Join the DZone community and get the full member experience.

Join For Free

The NetBeans 7.0 IDE provides several templates for new files created within the IDE.  This tip will demonstrate how you can easily embed your full name and email address into your Java class's Javadoc and also generate a license header comment at the top of your new files -- without editing the individual templates themselves.  This is accomplished by simply setting a couple of properties: 

  • The user property within the NetBeans IDE
  • The project.license property of your NetBeans project(s)

Example Java Class Template

Before we establish the user and project.license properties, let's first take a look at the default Java Class template (below) just to see how these properties are used. You can access (and edit) this template via:

  1. Select Tools | Templates
  2. Browse to Java > Java Class
  3. Select Open in Editor

Note the the placement of the user property in the JavaDoc and the context of project.license property within a filename string:

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>
/**
*
* @author ${user}
*/
public class ${name} {

}

 

User Property

Establishing the user property is simple:

  1. Select Tools | Templates | Settings
  2. Edit the User.properties file to establish the user property: e.g., user=your full name <your email/contact info>

By default the user property in the User.properties file is commented out.  Uncomment and edit this line to provide a pretty string to the template processor.  Note the possibility of adding other properties to this file and then using them in customized templates.

 

Project License Property

Generating a license header in your new files requires that you set the project.license property in your project's project.properties file to one of the files found in the Tools | Templates | Licenses folder.  However, the propery value must be set such that a proper filename string is created by the template processor.  The template processor builds a filename by prefixing "license-" and appending ".txt" to the project.license property. 

So, for example, to use the the license-gpl20.txt template (one of the files found in Tools | Templates | Licenses folder), perform the following steps:

  1. In the Project Explorer, navigate to <Your Project> | Important Files | Project Properties
  2. Add or Edit the project.license property: project.license=gpl20

 (The gpl20 property value is the license-gpl20.txt filename stripped of "license-" prefix and the ".txt" suffix.)

Some other built-in license templates that you can use via this technique include:

  • apache20
  • gpl20
  • gpl30
  • mit
Template Property (programming) NetBeans

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Synchronization Methods for Many-To-Many Associations
  • How to Determine if Microservices Architecture Is Right for Your Business
  • How to Leverage Method Chaining To Add Smart Message Routing in Java
  • Modern REST API Design Principles and Rules

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo