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):

  • 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:

My Strings Table now looks like this:

3.  COPYRIGHT3=Copyright (c) 2005 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.
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.
14.  COPYRIGHT14=Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
  • 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:
 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.