Netbeans file template module tutorial

Source: Internet
Author: User
Tags netbeans

This tutorial demonstrates how to create a module that contains a file template. After installing this module in IDE, you can use this file template in the new file wizard. With a module that contains a file template, it is easy to share the file template. netbeans ide 5.0 allows you to create a binary file that can be used by others, and then others install it through the update center.

A file template consists of a template file, an HTML description file, and an icon. The HTML description file displays information about the template in the new file wizard. Icon to identify the template and distinguish it from other templates in the new file wizard. In this tutorial, you can copy the content of an existing file template to an empty file to create a new file template. Then, set the description file and the difference icon for the new file wizard.Layer. xmlFile.

Note:If you use the new file type wizard, a file template is automatically created for you. When using the new file type wizard, the manual steps described in this tutorial are unnecessary. The new file type wizard also allows you to select the icon, which also creates an HTML description file. The new file type wizard automatically appears inLayer. xmlFile template, HTML description file, and icon. Therefore, if the file template you want to create is related to the new file type, you 'd better use the new file type wizard. For more information, see the netbeans dataloader module tutorial.

This tutorial introduces the following topics:

  • Install software
  • Create a module project
  • Create a file template
    • Create a template file
    • Create a description file
    • Get icon
  • Register a file template
  • Build and install modules

After installing the software, this tutorial can be completed within 20 minutes.

For more information about using the netbeans module, see the netbeans Development Project homepage on the netbeans website. If you have any questions, visit the netbeans developer FAQ or use the feedback link at the top of this page.


Install software

Before you begin, install the following software on your computer:

  • Netbeans ide 5.0 (download)
  • Java standard development kit (JDK) version 1.4.2 (download) or 5.0 (download)

Create a module project

     

  1. Select File> New Project (CTRL-shift-N ). Under categories, select netbeans plug-in modules. Under projects, select module project and click Next.

     

  2. On the name and location panel, TypeAdditionalfiletemplates. Change the project location to any directory on your computer, as shown in figureC:/mymodules. Select the standalone module radio button and the set as main project check box. Click Next.

     

  3. In the Basic module configuration panel, useMyorgReplaceYourorghereSo that the entire code name base isOrg. myorg. additionalfiletemplates. Add a space to the default module display name and change itAdditional file templates. Leave the location of the localization package and XML layer so that they are stored inOrg/myorg/additionalfiletemplates. Click Finish.

IDE CreationAdditional file templatesProject. This project contains all resources and project metadata, such as the ant build script of this project. This project is opened in IDE. You can view its logical structure in the projects window (Ctrl-1) and its file structure in the files window (Ctrl-2. For example, the projects window should be as follows:

For more information about each file, see the Quick Start Guide for the netbeans plug-in module.

Create a file template

A file template consists of a template file, an HTML description file, and an icon. A simple way to create a new file template is to copy the content of an existing file template to an empty file. Then, after setting the description file and the differentiation icon for the new file wizardLayer. xmlFile.

Create a template file

     

  1. Go to tools> template manager. Expand Java classes as follows:

     

  2. Select a Java class template and click Open in editor.

    The Java class template will be opened in source Editor:

    /* * __NAME__.java * * Created on __DATE__, __TIME__ * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package Templates.Classes;/** * * @author __USER__ */public class Class {    /** Creates a new instance of __NAME__ */    public Class() {    }}

    Note that the Java class template contains placeholders filled in when the new file wizard is used to create a file. The placeholders are as follows:

    • _ Name __. Replace it with the file name entered in the new file wizard.
    • Class. Replace with the class name entered in the new file wizard.
    • _ User __. Replace with the current user.
    • _ Date __. Replace with the current date.
    • _ Time __. Replace with the current time.

     

  3. Right-clickAdditional file templatesNode and select new> file/folder. In the new file wizard, select other under categories and empty file under file types. Click Next.

     

  4. In file name, typeBrandedjavaclass. Template. Click Browse and browseSrc/org/myorg/additionalfiletemplates. Click Select folder. Click Finish.

    ABrandedjavaclass. TemplateOpen the empty file in source editor, and its nodes are displayed in the projects window.

     

  5. Copy the content of the Java class templateBrandedjavaclass. TemplateFile.

     

  6. DirectionBrandedjavaclass. TemplateAdd Tag Information to the top of the file. For example, add Sun Microsystems copyright information to the top of the file.
    /* * Copyright (c) 2005 Sun Microsystems, Inc.  All rights reserved.  U.S. * Government Rights - Commercial software.  Government users are subject * to the Sun Microsystems, Inc. standard license agreement and * applicable provisions of the FAR and its supplements.  Use is subject * to license terms. * * This distribution may include materials developed by third parties. * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks * or registered trademarks of Sun Microsystems, Inc. in the U.S. and * other countries. * * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves. * * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions * en vigueur de la FAR (Federal Acquisition Regulations) et des * supplements a celles-ci.  Distribue par des licences qui en * restreignent l'utilisation. * * Cette distribution peut comprendre des composants developpes par des * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE * sont des marques de fabrique ou des marques deposees de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */

     

  7. Press ctrl-s to save the file.
Create a description file

     

  1. Right-clickOrg. myorg. additionalfiletemplatesNode, and then select new> file/folder. Under categories, select other. Under file types, select HTML file. Click Next. In file name, typeDesc_brandedjavaclass. Click Browse and browseSrc/org/myorg/additionalfiletemplates. Click Select folder. Click Finish.

    An empty HTML file is opened in the source editor, and its nodes are displayed in the projects window.

     

  2. In<Body>Enter"Creates Java class branded with <B> Sun Microsystems </B> copyright text."(No quotation marks) to make the file look as follows:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

     

  3. Press ctrl-s to save the file.
Get icon

The icon is accompanied by the file template in the new file wizard. It identifies itself and distinguishes itself from other file templates. The Icon size must be 16x16 pixels. If you do not have your own icons, you can find some 16x16 icons in the netbeans ide 5.0 installation directory:

enterprise2/jakarta-tomcat-5.5.7/server/webapps/admin/images

Name the iconIcon_brandedjavaclassAnd add itOrg. myorg. additionalfiletemplatesPackage.

The projects window should be displayed as follows:


Register a file template

After creating a file template, you must register it in netbeans system filesystem.Layer. xmlThe file is used for this purpose.

  1. InLayer. xmlFile<Filesystem>Add the following entries between tags:

     

    <folder name="Templates">   <attr name="Classes/BrandFiles" boolvalue="true" />   <attr name="BrandFiles/GUIForms" boolvalue="true" />   <folder name="BrandFiles">   <attr name="SystemFileSystem.localizingBundle" stringvalue="org.myorg.additionalfiletemplates.Bundle"/>       <file name="BrandedJavaClass.java" url="BrandedJavaClass.template">          <attr name="template" boolvalue="true"/>          <attr name="SystemFileSystem.localizingBundle" stringvalue="org.myorg.additionalfiletemplates.Bundle"/>          <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/myorg/additionalfiletemplates/Icon_BrandedJavaClass.gif"/>          <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.ui.wizard.JavaWizardIterator.singleton" />          <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/myorg/additionalfiletemplates/Desc_BrandedJavaClass.html"/>       </file>  </folder></folder>

    The above mark is explained below:

    • ATTR name = "classes/brandfiles".Place the brandfiles category under the classes category.
    • ATTR name = "brandfiles/guiforms".Place the brandfiles category on the guiforms category.
    • Folder name = "brandfiles".The common name of category in the new file wizard.Bundle. Properties.
    • ATTR name = "systemfilesystem. localizingbundle".The name and location of the localized package.

       

    • File name = "brandedjavaclass. Java".The common name of file type in the new file wizardBundle. Properties.
    • Url = "brandedjavaclass. template".The location and name of the template in the source structure.
    • File attributes:
      • Template.This is a template.
      • Systemfilesystem. localizingbundle.The name and location of the localized package.
      • Systemfilesystem. icon.The name and position of the icon.
      • Instantiatingiterator.(Coming soon)
      • Instantiatingwizardurl.The name and location of the HTML description file.

     

  2. Add the display nameBundle. PropertiesFile:

     

    Templates/BrandFiles=Branded FilesTemplates/BrandFiles/BrandedJavaClass.java=Branded Java Class

    The above strings are explained below:

    • Templates/brandfiles.The display name of the folder named "brandfiles.
    • Templates/brandfiles/brandedjavaclass. Java.The display name of the file "brandedjavaclass. Java.


Build and install modules

IDE uses the ant build script to build and install your module. The build script is created when you create a module project.

Install the netbeans Module
  • In the projects window, right-clickAdditional file templatesProject and select install/reload in target platform.

    The module is constructed and installed in the target ide or platform. Open the target ide or platform. You can try a new module. The default target ide or platform is the installation platform used by the current ide instance. Note that when you run the module, you will use the temporary test user directory instead of the IDE user directory.

Use the netbeans Module
  1. Select File> New Project (CTRL-shift-N) to create a new project.
  2. Right-click the project and choose new> file/folder. The new file wizard is opened, and the new category and new file type are displayed. Its appearance is similar to the following, but your icons may be different:

  3. Select the new file type, click Next, and create a new file. After you click Finish, the source editor displays the newly created template.
Create a shared module binary file
  1. In the projects window, right-clickAdditional file templatesProject, and select create NBM.

    The NBM file will be created and can be viewed in the files window (Ctrl-2 ):

  2. You can use it by email.

Next step

For more information about creating and developing the netbeans module, see the following resources:

     

  • Plug-in developer Resources

     

  • Netbeans API list (current development version)

     

  • New API support suggestions

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.