DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Introduction To Git
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Authorization: Get It Done Right, Get It Done Early

Trending

  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Introduction To Git
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Authorization: Get It Done Right, Get It Done Early
  1. DZone
  2. Coding
  3. Tools
  4. Personalized Code Templates in NetBeans 7.0

Personalized Code Templates in NetBeans 7.0

Bruce Schubert user avatar by
Bruce Schubert
·
Apr. 29, 11 · Interview
Like (1)
Save
Tweet
Share
30.03K 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.

Trending

  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Introduction To Git
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Authorization: Get It Done Right, Get It Done Early

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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

Let's be friends: