PackageTemplateTutorial

PackageTemplatesTutorial

This tutorial guides you using the package-template plugin.

Contents

Introduction

The plugin offers some templates which generate a package hierarchy.

The idea is that you start creating your application package names, like org.{organization}.{application}, conventionally. Next you select one of the package templates, and the packages defined in the template are created.

Using the package-template plugin helps you to have a consistent package naming across your projects.

Steps to Reproduce

  1. Download the package-template plugin from http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=6250
  2. Create a Project, or open an existing project.
  3. Select a package in the explorer view.
  4. Invoke the File|New File.., alternativly select New from the context-menu.
  5. Select an appropriate template from the category Package
  6. Choose the source group and base package name
  7. Finish the wizard

The following screen shot shows the available package-templates available, so far:
http://wiki.netbeans.org/attach/PackageTemplateTutorial/package-templates-wizard_PackageTemplateTutorial.gif

After selecting a package template the screen, a wizard page shows up, allowing to choose the source group and the base package name:
http://wiki.netbeans.org/attach/PackageTemplateTutorial/package-templates-wizard-2_PackageTemplateTutorial.gif

The package-templates plugin asks you when a file in the template is about to overwrite an already existing file.

A dialog like shown below pops up:
http://wiki.netbeans.org/attach/PackageTemplateTutorial/package-templates-dialog_PackageTemplateTutorial.gif

  • Select No, when you don't want to overwrite the existing file.
  • Select Yes, when you want to replace the existing file by the template file.
  • Select Cancel, when you want to cancel the template processing.

Expected Result

The selected package template creates the packages, and files relative to selected base package.

For example: selecting foo.bar as base package, running the service package template creates following packages:

  • foo.bar.dao
  • foo.bar.domain
  • foo.bar.service

The screen shot below shows the created packages in the project explorer view:
http://wiki.netbeans.org/attach/PackageTemplateTutorial/package-templates-result_PackageTemplateTutorial.gif

Moreover the service package template creates simple package documentation for each package, explaining the which classes, and interfaces are expected to reside in this package.


Further Thoughts using package-templates plugin

Existing Naming conventions

The project directory structure is quite well defined. Starting from the project directory, Jakarta Apache, and Sun have conventions about the grand project layout, like put your built artifacts under the build directory, and store your source files in src, or src/java. Moreover maven guides you to using its project directory layout conventions, like put your sources under the src directory, and the built artifacts are put under the target directory.

Jumping to the java coding guidelines: The name of the packages, and of classes are defined in the Java Coding Guidelines. These kind of coding guidelines even talk about space versus tab. So the details how-to name classes, package, variables, are well defined, too.

But there is something missing...

Package templates

The package templates try to fill the gap between the project directory layout conventions, and the coding style guidelines, by offering a package hierarchy for some project types, like struts, spring-mvc, service-layer, etc.

I think it will be helpful if there is a convention how to name your packages across projects.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo