java left logo
java middle logo
java right logo

Home arrow Other API Tips arrow NetBeans arrow Centralized Variables in NetBeans IDE Strings Tables
Main Menu
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog

Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews

Registered Users: 4118
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
Centralized Variables in NetBeans IDE Strings Tables E-mail
User Rating: / 6


The file template is branded with the Sun Microsystems copyright text. However, I've just discovered a different way of branding a file. It's not the most efficient way of doing so, but it is fun because it is different. Maybe it will give you some ideas of doing other similar things.


There are really only two steps to this process (which is another cool thing about this approach):

  1. Define copyright variables in a Strings Table. Go to Tools > Options. In the Options dialog box, expand Editing, select Java Sources, and click Strings Table. The Java Sources - Strings Table dialog box pops up. By default, only the USER variable is defined. So now, just add a string for each line of the copyright text, and include some spacing:

  2. 1.  COPYRIGHT1=
    2.  COPYRIGHT2=
    3.  COPYRIGHT3=Copyright (c2005 Sun Microsystems, Inc.  All rights reserved.  U.S.
    4.  COPYRIGHT4=Government Rights - Commercial software.  Government users are subject
    5.  COPYRIGHT5=to the Sun Microsystems, Inc. standard license agreement and
    6.  COPYRIGHT6=applicable provisions of the FAR and its supplements.  Use is subject
    7.  COPYRIGHT7=to license terms.
    8.  COPYRIGHT8=
    9.  COPYRIGHT9=This distribution may include materials developed by third parties.
    10.  COPYRIGHT10=Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
    11.  COPYRIGHT11=or registered trademarks of Sun Microsystems, Inc. in the U.S. and
    12.  COPYRIGHT12=other countries.
    13.  COPYRIGHT13=
    14.  COPYRIGHT14=Copyright (c2005 Sun Microsystems, Inc. Tous droits reserves.
    15.  COPYRIGHT15=
    16.  COPYRIGHT16=

    My Strings Table now looks like this:


  3. Specify the copyright variables in a file template. Again in the Options dialog box, expand Source Creation and Management, expand Templates, and then find a Java template to which you want to add the copyright text. For example, expand Java Classes, select Java Class, right-click it and choose Open. The template opens in the Source Editor. Now add all the variables you defined to the template:

  4. 1.  /*
    2.   *
    3.   *
    4.   * Created on __DATE__, __TIME__
    5.   *
    6.   * __COPYRIGHT1__
    7.   * __COPYRIGHT2__
    8.   * __COPYRIGHT3__
    9.   * __COPYRIGHT4__
    10.   * __COPYRIGHT5__
    11.   * __COPYRIGHT6__
    12.   * __COPYRIGHT7__
    13.   * __COPYRIGHT8__
    14.   * __COPYRIGHT9__
    15.   * __COPYRIGHT10__
    16.   * __COPYRIGHT11__
    17.   * __COPYRIGHT12__
    18.   * __COPYRIGHT13__
    19.   * __COPYRIGHT14__
    20.   * __COPYRIGHT15__
    21.   * __COPYRIGHT16__
    22.   *
    23.   */
    25.  package Templates.Classes;
    27.  /**
    28.   *
    29.   * @author __USER__
    30.   */
    31.  public class Class {
    33.      /** Creates a new instance of __NAME__ */
    34.      public Class() {
    35.      }
    37.   }

When you save the file, you've changed the template. So when you create a new Java class in the New File wizard, all the variables above will be replaced by the values in the Strings Table. A question you might be asking right now is: "Why don't you just put the copyright text straight into the template? What's the point of defining all those variables in the Strings Table in the first place?" Good question. The answer: What happens if the copyright text changes? If I'd defined the copyright text in the template, I'd have to change it in the template -- as well as in every other template where I defined the copyright text. By defining the copyright text in the Strings Table, I've got one centralized place where I can edit the copyright text. (At the very least, COPYRIGHT3 and COPYRIGHT14 will change once a year!) Of course, what this approach doesn't support is the ability to share the file template with others -- that's where the NetBeans plug-ins come in handy because the end-product of plug-in development is a binary file that you can easily transfer to a colleague, via e-mail, disk, or shared server.

 Related Tips

< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.

Name (required)

E-Mail (required)

Your email will not be displayed on the site - only to our administrator

Comment Enable HTML code : Yes No

java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008
Java is a trademark of Sun Microsystems, Inc.