Sie sind auf Seite 1von 6

Using Project Templates

March 2006 [Revision number: V2-1]


Copyright 2006 Sun Microsystems, Inc.

This tutorial describes how to create and use user project templates in the Sun Java Studio Creator integrated development environment (the IDE). Contents - About Project Templates - Saving a Project as a Template - Creating a New Project From a Project Template - Managing the List of User Project Templates Example used in this tutorial project-templates_ex.zip included in the downloaded ZIP file.

About Project Templates


When you create a new project, the Sun Java Studio Creator IDE bases the project on a project template and uses the template to create a directory structure under the main project directory. The IDE then populates the directory structure with all the source files and library references needed to support your application. The Sun Java Studio Creator IDE enables you to use two types of project templates when you create a project:
q

Built-in templates. These templates are supplied by the IDE to create various kinds of new projects. When you create a new project, for example, by clicking the Create New Project button in the Welcome window, the New Project wizard opens and shows a list of project templates in its Projects list. The default project template is JSF Web Application. You can see different sets of templates by selecting a different item in the Categories list on the left. User project templates. You create and save these templates from existing projects. A user project template is a complete copy of a project and can include style sheets, pages, page fragments, login forms, and so on. You can create a template from any type of IDE project, including JSF web projects, JSR-168 JSF Portlet projects, and Java library projects. If you have created templates, you can see them either by choosing Tools > Project Template Manager or by choosing File > New Project to open the New Project wizard, and then selecting My Templates in the Categories list. The Project Template Manager enables you to manage the list of project templates, and you can use this dialog box to add a template to the list or remove a template.

This tutorial shows you two ways to save a project as a template, and also shows you how to open a new project that uses the project template that you created. Some common uses for user project templates:
q

To enforce styles and layouts. You can use a template to create an initial, standardized layout for applications. For example, you can create a template from a project that complies with your organization's design policies. Departments within an organization can publish a folder of templates and enable all users to access them directly from the Java Studio Creator IDE. In these cases, the templates enforce design features and typically have little content of their own. To set up your programming environment. You can use templates to provide an empty project with a number of predefined library references for specific applications. These libraries can contain references to commonly used business logic, Javadoc documentation, and source libraries, or they can contain special support classes for a specific deployment container. To aid iterative development. You can use templates to assist in prototyping, experimentation, and iterative development. For example, you can save a working application as a template, and then create a new project from the template and attempt to enhance it. If the effort fails, you can easily abandon the project and start fresh from the template. If the effort is successful, you can save the modified project as a template for use as a point of reference.

Saving a Project as a Template


In this section, you open an example project file that contains a welcome page and a newsletter page for Sky Company. The example uses page fragments to provide a header and a left navigation bar that can be used across all pages in the application. You save the project as a template to provide all web application developers at Sky Company with the same starting point for their projects.

1. If you have not done so already, download project-templates_ex.zip to a local directory. Open the file and extract its contents into the Sun Java Studio Creator project directory. On Windows systems, the path to this directory is typically the following: C:\Documents and Settings\user-name\My Documents\Creator\Projects 2. In the IDE, choose File > Open Project and open the ProjTemplate project. 3. When the project has loaded, click the Run Main Project button to ensure that the project builds and runs correctly.

In your browser, you should see a page with a hyperlink to Company News. Clicking the Company News link takes you to a second page that shows the latest news for the company, "We have a new chief executive officer." 4. In the Projects window, right-click the ProjTemplate node and choose Save Project As. 5. In the Save Project as Template dialog box, check the Add Project to Template List checkbox, and then enter SkyCompany for the Project Name. The dialog box updates the project location, as shown in the following figure.

Figure 1: Save Project As Template Dialog Box 6. Click OK to save the project as a template. As you will see in the next section, the My Templates node is added to the New Projects wizard, and the SkyCompany template is listed as one of the project templates. 7. Choose File > Close "ProjTemplate" to close the project.

Creating a New Project From a Project Template


In this section, you create a new project from your SkyCompany project template. 1. In the IDE, choose File > New Project. In the following figure, there is now a My Templates category, which was added to the Categories list when you created the SkyCompany template.

Figure 2: New Project Wizard 2. In the New Project wizard, under Categories, select My Templates, and under Projects, select the SkyCompany template, and then click Next. The next page of the wizard opens, the New JSF Web Application page. 3. Enter TestApplication in the Project Name field. The Project Folder and Default Java Package fields change to match the new name, as shown in the following figure.

Figure 3: New JSF Web Application Wizard Page 4. Click Finish to create the TestApplication project based on your SkyCompany template. The new project based on the SkyCompany template opens in the Projects window. You can now extend this project without affecting the original project.

Managing the List of User Project Templates


In Saving a Project as a Template, you created a template from a project by right-clicking the project's node in the Projects window and choosing Save Project As, and then renaming the template. There is another way to add a template, by using the Project Template Manager. This technique enables you to create a template from any of your projects without first having to open the project. The template you create has the same name as the project. This section uses the sample TravelCenter project, which uses a database. If the bundled database is not running, right-click the Bundled Database Server node in the Servers window and choose Start Bundled Database. 1. Choose File > New Project. 2. In the New Project wizard, select the Samples category, and then select the TravelCenter project and click Next. 3. Name the project TravelCenter, and then click Finish to create the project from the sample. 4. Choose Tools > Project Template Manager. The Project Template Manager dialog box opens. In the following figure, you see the SkyCompany template created earlier in this tutorial.

Figure 4: Project Template Manager Dialog Box 5. Click Add to create a new template from an existing project. The Open Project dialog box opens, showing all the projects you have opened in the IDE.

Figure 5: Open Project Dialog Box 6. Select the TravelCenter project, and then click Open Project Folder. A project template is created with the same name as the project you selected, TravelCenter, and the template is added to the list of templates in the Project Template Manager dialog box. 7. Click OK to close the Project Template Manager dialog box. Note: You can remove any template listed in the Project Template Manager by selecting the template and clicking Remove.

See Also:
q

Using Page Fragments

This page was last modified: March 16, 2006

Sun and Third-party Trademarked Terminology


The following Sun trademarked terms might be used in the Sun Java(tm) Studio Creator tutorials:
q q q q q q q q q

Sun Java Studio Creator integrated development environment (IDE) Sun Java System Application Server version number (Application Server) Java Platform, Standard Edition technology (Java SE(tm) platform) JavaServer(tm) Faces technology JavaServer Pages(tm) technology (JSP(tm) technology) Sun Java System Web Server version number (Web Server) Java Database Connectivity software (JDBC software) Enterprise JavaBeans(tm) specification (EJB(tm) specification) Solaris(tm) Operating System software (Solaris OS software)

The following third-party trademarked terms might be used in the Sun Java Studio Creator tutorials:
q q

UNIX(R) software SPARC(R) processor

Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at http://www.sun.com/ patents and one or more additional patents or pending patent applications in the U.S. and in other countries. 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. Sun, Sun Microsystems, the Sun logo, Java and the Java Coffee Cup logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.This product is covered and controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited. Note: Sun is not responsible for the availability of third-party web sites mentioned in this document and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. Sun will not be responsible or liable for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods, or services available on or through any such sites or resources.

Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, tats-Unis. Tous droits rservs. Sun Microsystems, Inc. dtient les droits de proprit intellectuels relatifs la technologie incorpore dans le produit qui est dcrit dans ce document. En particulier, et ce sans limitation, ces droits de proprit intellectuelle peuvent inclure un ou plus des brevets amricains lists l'adresse http://www.sun.com/patents et un ou les brevets supplmentaires ou les applications de brevet en attente aux tats-Unis et dans les autres pays. L'utilisation est soumise aux termes de la Licence. Sun, Sun Microsystems, le logo Sun, Java et le logo Java Coffee Cup sont des marques de fabrique ou des marques dposes de Sun Microsystems, Inc. aux tats-Unis et dans d'autres pays.Ce produit est soumis la lgislation amricaine en matire de contrle des exportations et peut tre soumis la rglementation en vigueur dans d'autres pays dans le domaine des exportations et importations. Les utilisations, ou utilisateurs finaux, pour des armes nuclaires,des missiles, des armes biologiques et chimiques ou du nuclaire maritime, directement ou indirectement, sont strictement interdites. Les exportations ou rexportations vers les pays sous embargo amricain, ou vers des entits figurant sur les listes d'exclusion d'exportation amricaines, y compris, mais de manire non exhaustive, la liste de personnes qui font objet d'un ordre de ne pas participer, d'une faon directe ou indirecte, aux exportations des produits ou des services qui sont rgis par la lgislation amricaine en matire de contrle des exportations et la liste de ressortissants spcifiquement dsigns, sont rigoureusement interdites. Sun Microsystems n'est pas responsable de la disponibilit de tiers emplacements d'enchanement mentionns dans ce document et n'approuve pas et n'est pas responsable ou iresponsable d'aucun contenu, de la publicit, de produits, ou d'autres matriaux dessus ou fournis par de tels emplacements ou ressources. Sun ne sera pas responsable ou iresponsable d'aucuns dommages ou perte causs ou allgus pour tre caus par ou en liaison avec l'utilisation de ce produit ou la confiance dans des tels contenu, marchandises, ou services disponibles sur ou par des tels emplacements ou ressources.

Das könnte Ihnen auch gefallen