# Application and Project Templates

This topic explains what application and project templates are and how to define custom templates in the WebLogic Workshop IDE.

## What are Application and Project Templates?

Templates are a mechanism for pre-loading new WebLogic Workshop applications and projects into the IDE. The same mechanism is used by WebLogic Workshop whenever a user creates a new application or a new project in an existing application. A set of standard application templates are used to create web, portal and business process type applications. A set of standard projects templates are used to create Java class library, XML Schema libraries, EJB, business process, web service, web application and Java control projects.
To load an application template into the IDE, the user selects File-->New-->Application and is presented with the New Application dialog displayed below:

Users can select an application category on the left side of the dialog, and a particular template within that category on that right side of the dialog. A description of the template is displayed at the bottom of the dialog. User can also specify the directory where the application code will reside, the application name, and the application server.
To load a new project template into an already existing application, users select File-->New-->Project and complete the New Project dialog.

## Defining Custom Application and Project Templates

Individual application and project templates are stored in the [BEA_HOME]/weblogic81/workshop/template directory. In order for individual templates to appear in the New Application and New Project dialogs, they must be present in the directory prior to the start of the IDE.

Templates are packaged as ZIP files containing (1) a template.xml file and (2) any other content included as part of the new application or project. Zip files in the /templates directory containing a template.xml file will be read each time a user opens a New Application, New Project, or Add Project dialog. A template.xml file may contain any number of project template (<project-template>) or application template (<application-template>) elements, each defining a entry displayed in the dialogs.

Note that the top-level template ZIP file may contain other ZIP files within it. For example, the application template Tutorial: Hello World Process Application (see the image above), is contained in the ZIP file wli-helloworld.zip, which, contains two ZIP files within it: default-project.zip and default-schemas-project.zip:

/templates/wli-helloworld/templates.xml
/templates/wli-helloworld/Schemas.jar
/templates/wli-helloworld/default-project.zip
/templates/wli-helloworld/default-schemas-project.zip

(1) The template.xml file defines which projects and other content are included in the application template.

(2) The default-project.zip and default-schemas-project.zip files contain all the source code content that is included in this application template. For example, a simple process, HelloWord.jwf, is included in this template, as well as a set of schema files.
The template.xml contains the following template definition:

    <template-definition>

        <project-template id="hello_world_process_project"
            type="urn:com-bea-ide:project.type:WebApp">
            <content type="archive" destination="project" source="default-project.zip"/>
        </project-template>

        <project-template id="hello_world_schemas"
            type="urn:com-bea-ide:project.type:Schema">
            <content type="archive" destination="project" source="default-schemas-project.zip"/>
            <content type="file" destination="libraries" source="Schemas.jar"/>
        </project-template>

        <application-template id="hello_world_process_app">
            <display
                location="newdialog"
                label="Tutorial: Hello World Process Application"
                description="Creates a new Process application containing a simple hello world Process project."
                priority="20"
                categories="Tutorial"/>
            <project-template-ref type="urn:com-bea-ide:project.type:WebApp" template="hello_world_process_project"/>
            <project-template-ref default-name="Schemas" type="urn:com-bea-ide:project.type:Schema" template="hello_world_schemas"/>
        </application-template>

    </template-definition>

As illustrated above each <template-definition> element can contain two types of templates, application and/or project. In this case the definition contains both type but could contain one or the other.
The <application-template> above is displayed in the New Application dialog in the following way.
The template.xml file can also define any number of projects along with their source code content to pre-load in the IDE. Also, each <project-template> element has an id attribute that must uniquely identify it from all other project templates. The id allows an <application-template> to reference <project-templates> in order to pre-load a new application with specific projects and their content. Notice how the <application-template> element contains two <project-template-ref> elements that reference corresponding <project-template> elements.

Note that the referenced <project-template> elements can exist in the same template.xml definition or in a completely different template.xml definition in a different template ZIP file. In other words, a <application-template> can potentially reference all project templates contained in the WebLogic Workshop /template directory.

## Extending Templates

Note that a project (or application) template can extend another project (or application) template. Display information in the extended template will not be inherited. But content from the extended template will be inherited. For example assume that you have a project template with id="baseProj".

        <project-template id="baseProj" type="urn:com-bea-ide:project.type:WebApp">
            ...
        </project-template>

Another project template can extend this project template by pointing to its id.

        <project-template id="someOtherProject" type="urn:com-bea-ide:project.type:WebApp" extends="baseProj">
            ....
        </project-template>

Note that the extended and the extending project templates must be of the same type.

The extended and extending templates need not exist in the template.xml file, nor need they exist in the same ZIP file. When Workshop encounters an extending template, it will search all template.xml files within [BEA_HOME]/weblogic81/workshop/template for the extended template.

## Localizing Templates

There is currently no support for automatic localization of templates: application and project templates must be localized manually. Template developers should produce a different template ZIP file for each location.

Related Topics

template.xml Reference