Sun GlassFish Enterprise Server v3 Application Deployment Guide

Chapter 1 Overview of Sun GlassFish Enterprise Server v3 Application Deployment

Sun GlassFishTM Enterprise Server v3 provides an environment for developing and deploying JavaTM applications and web services. Enterprise Server applications include Java Platform, Enterprise Edition (Java EE platform) standard features as well as Enterprise Server–specific features. This guide explains the tools and processes used for deploying applications and modules in the Enterprise Server environment. Only Enterprise Server–specific features are described in detail in this document.

The following topics are addressed here:

Information and instructions on deploying from the command line are provided in this document. Information and instructions for accomplishing the deployment tasks by using the Administration Console are contained in the Administration Console online help.

About Application Deployment

Assembly, also known as packaging, is the process of combining discrete components into a single unit that can be installed on an application server. The Enterprise Server assembly process conforms to the customary Java EE specifications. The only difference is that when you assemble applications or modules in Enterprise Server, you can include optional Enterprise Server–specific deployment descriptors that enhance functionality.

Deployment is the process of using a deployment tool to specify location-specific information, such as a list of local users that can access the application, or the name of the local database. The deployment tool expands the archive file into an open directory structure that is ready for users. Enterprise Server deployment tools are described in About Deployment Tools.

The following topics are addressed here:

General Deployment Functionality

Various Java EE module types, such as connector module, web module, EJB module, application client module, can be deployed in the following ways:

A deployment plan, which deploys a portable archive along with a deployment plan containing Enterprise Server– specific deployment descriptors, can apply to any of these deployment techniques. For instructions, see To Deploy an Application or Module by Using a Deployment Plan.

There are two work situations that require different safeguards and processes:

Some deployment methods that are used effectively in a development environment should not be used in production. For example, dynamic reloading is a quick way for developers to reload an application, but might degrade performance in a production environment. In addition, whenever a reload is done, the sessions that are in transit become invalid, which might not be a concern for development, but can be a serious matter in production. The client must restart the session, another negative in a production environment.

Deployment Descriptors and Annotations

A deployment descriptor is an XML file that describes how a Java EE application or module should be deployed. Each deployment descriptor XML file has a corresponding Document Type Definition (DTD) file or schema (XSD) file, which defines the elements, data, and attributes that the deployment descriptor file can contain. The deployment descriptor directs a deployment tool to deploy a module or application with specific container options, and also describes specific configuration requirements that you must resolve.

Because the information in a deployment descriptor is declarative, it can be changed without requiring modifications to source code. At run time, Enterprise Server reads the information in the deployment descriptor and deploys the application or module as directed.

The following types of deployment descriptors are associated with Enterprise Server:

An annotation, also called metadata, enables a declarative style of programming. You can specify information within a class file by using annotations. When the application or module is deployed, the information can either be used or overridden by the deployment descriptor. Enterprise Server supports annotation according to the following specifications:

The following annotation and deployment descriptor combinations are supported:

Modules and Applications

A module is a collection of one or more Java EE components that run in the same container type, such as a web container or EJB container. The module uses annotations or deployment descriptors of that container type. You can deploy a module alone or as part of an application.

The following topics are addressed here:

Types of Modules

Enterprise Server supports the following types of modules:

Module–Based Deployment

You can deploy web, EJB, and application client modules separately, outside of any application. Module–based deployment is appropriate when components need to be accessed by other modules, applications, or application clients. Module-based deployment allows shared access to a bean from a web, EJB, or application client component. By using package definitions in the source code of all modules, you eanble the class loader to properly locate the classes after the modules have been deployed.

The following figure shows separately-deployed EJB, web, and application client modules.

Figure 1–1 Module–Based Assembly and Deployment

Figure shows EJB, web, and `application client module
assembly and deployment.

Application-Based Deployment

An application is a logical collection of one or more modules joined by application annotations or deployment descriptors. You assemble components into JAR, WAR, or RAR files, then combine these files into an Enterprise archive (EAR) file which is deployed.

The following figure shows EJB, web, application client, and connector modules assembled into a Java EE application.

Figure 1–2 Application–Based Assembly and Deployment

Figure shows Java EE application assembly and deployment.

Access to Shared Framework Classes

If you assemble a large, shared library into every module that uses it, the result is a huge file that takes too long to register with the server. In addition, several versions of the same class could exist in different class loaders, which is a waste of resources. When Java EE applications and modules use shared framework classes (such as utility classes and libraries), the classes can be put in the path for the common class loader or an application-specific class loader rather than in an application or module. For more information, see Chapter 2, Class Loaders, in Sun GlassFish Enterprise Server v3 Application Development Guide.

Note –

According to the Java EE specification, section, “Dependencies,” you cannot package utility classes within an individually-deployed EJB module. Instead, you must package the EJB module and utility JAR within an application using the JAR Extension Mechanism Architecture.

Naming Standards

Names of applications and individually-deployed modules must be unique within an Enterprise Server domain. Modules within an application must have unique names.

Note –

Ensure that your package and file names do not contain spaces or characters that are illegal for your operating system.

You should use a Java package-like naming scheme for module file names, module names as found in the module-name portion of the ejb-jar.xml files, and EJB names as found in the ejb-name portion of the ejb-jar.xml files. This package-like naming scheme ensures that name collisions do not occur. The benefits of this naming practice apply not only to Enterprise Server, but to other Java EE application servers as well.

The following topics are addressed here:

Portable Naming

The Java EE 6 specification defines the portable application-name, which allows you to specify an application name in the application.xml file. For example:


This name is used before the archive name to derive the default application registration name. The application will be deployed under xyz if the application.xml file defines application-name as xyz. However, a user-specified name takes precedence over the portable application name. If application-name is not specified in the application.xml file, the application is deployed using the archive name (minus suffix) as the application registration name.

The Java EE 6 specification also defines the portable module-name element in the module standard deployment descriptors. For standalone modules, the defined module-name will be used as the application name when a name is not explicitly specified.

JNDI Naming

Java Naming and Directory InterfaceTM (JNDI) lookup names for EJB components must also be unique. Establishing a consistent naming convention can help. For example, appending the application name and the module name to the EJB name is a way to guarantee unique names, such as, jms/qConnPool.

Directory Structure

Application and module directory structures must follow the structure outlined in the Java EE specification. During deployment, the application or module is expanded from the archive file to an open directory structure. The directories are named with _jar and _war suffixes.

If you deploy a directory, your directory structure must follow this same convention. For instructions on performing directory deployment, see To Deploy an Application or Module in a Directory Format.

JSR 88 Naming

There are two JSR 88 APIs that can be used to deploy applications in Enterprise Server.

If you are using the following JSR 88 API, there is no file name:

javax.enterprise.deploy.spi.DeploymentManager.distribute(Target[], InputStream, InputStream)

Because there is no file name, the name of the application is taken from the display-name entry in the Java EE standard deployment descriptor. If the display-name entry is not present, Enterprise Server creates a temporary file name and uses that name to deploy the application. Neither the Administration Console nor the asadmin utility uses this API.

If you are using the following preferred JSR 88 API, the name is derived from the first portion of the file name (without the .war or .jar extension):

javax.enterprise.deploy.spi.DeploymentManager.distribute(Target[], File, File)

For more information about JSR 88, see

About Assembly and Deployment Events

The deployment tools that are provided by Enterprise Server can be used by anyone to deploy applications and modules into any Enterprise Server environment. However, effective application deployment requires planning and care. Only the developer knows exactly what is required by an application, so the developer is responsible for initial assembly and deployment.

  1. Deployment Descriptor Creation. The developer creates the deployment descriptors using Java standards and tools.

    Details of the Enterprise Server-specific deployment descriptors are contained in Appendix B, Enterprise Server Deployment Descriptor Files and Appendix C, Elements of the Enterprise Server Deployment Descriptors. The Enterprise Server–specific sample applications contain deployment descriptors that can be used as templates for developing deployment descriptors.

  2. Assembly. The developer assembles the archive file(s) using Java standards and tools, such as the jar command. The application or module is packaged into a JAR, WAR, RAR, or EAR file. For guidelines on naming, see Naming Standards.

    There are no Enterprise Server–specific issues to consider.

  3. Test Deployment. The developer performs a test deployment of the archive. For instructions, see To Deploy an Application or Module.

  4. Archive Submission. The developer submits the verified archive to the administrator for deployment into a production environment. The developer includes instructions for any additional deployment tasks that the administrator must perform. For an example of such additional instructions, see Access to Shared Framework Classes.

  5. Configuration. The administrator applies additional deployment specifics. Sometimes the developer has indicated additional deployment needs, such as specifying the production database. In this case, the administrator edits and reassembles the archive.

  6. Production Deployment. The administrator deploys the archive to production. See To Deploy an Application or Module.

  7. Troubleshooting. If deployment fails, the administrator returns the archive to the developer. The developer fixes the problem and resubmits the archive to the administrator. Sometimes the administrator resolves the problem, depending on what the problem is.

About Deployment Tools

The following tools can be used for assembling and deploying a module or application:

Administration Console

The Enterprise Server Administration Console is a browser-based utility that features a graphical interface that includes extensive online help for the administrative tasks. The format for starting the Administration Console in a web browser is http://hostname:port. For example:


Step-by-step instructions for using the Administration Console for deployment are provided in the Administration Console online help. You can display the help material for a page by clicking the Help button. The initial help page describes the functions and fields of the page itself. To find instructions for performing associated tasks, click a link in the See Also list.

The asadmin Utility

The Enterprise Server asadmin utility is a command-line tool that invokes subcommands for identifying the operation or task that you want to perform. You can run asadmin commands either from a command prompt or from a script. The format for starting the asadmin utility on the command line is as-install/bin/asadmin subcommand --option. For example:

asadmin list-applications --type web

Application deployment commands are listed in Appendix A, The asadmin Deployment Subcommands. All Enterprise Server asadmin commands are documented in Sun GlassFish Enterprise Server v3 Reference Manual.

For the most part, you can perform the same administrative tasks by using either the graphical Administration Console or the asadmin command-line utility, however, there are exceptions. Procedures for using the command-line utilities are provided in this guide and in the command-line help pages, which are similar to man pages. You can display the help material for a command by typing help followed by the subcommand. For example:

asadmin help list-applications

For additional information on the asadmin utility, see Using the asadmin Utility in Sun GlassFish Enterprise Server v3 Administration Guide and the asadmin(1M) help page.

Ant Utility

The Enterprise Server Ant tasks can help you assemble and deploy modules and applications. For instructions, see Chapter 3, Using Ant with Enterprise Server, in Sun GlassFish Enterprise Server v3 Application Development Guide.

Note –

Enterprise Server is compatible with Apache Ant versions 1.6.5 or greater. If you have not installed Ant, you can download it from the Update Tool. The Apache Ant Build Tool add-on component supplies Ant version 1.7.1. For information about Update Tool, see Update Tool in Sun GlassFish Enterprise Server v3 Administration Guide.

NetBeans IDE

You can use the NetBeansTM Integrated Development Environment (IDE), or another IDE, to assemble Java EE applications and modules. The NetBeans IDE is included in the tools bundle of the Java EE Software Development Kit (SDK). To download, see For additional information, see

Eclipse IDE

In addition to the bundled NetBeans IDE, a plug-in for the Eclipse IDE extends GlassFish to the Eclipse community. To download, see

JSR 88 Client

The syntax of the URI entry for the getDeploymentManager method is as follows:


Additional Information on Application Deployment

As specified from Java EE 6 specifications, the relevant specifications are the following:

The following product documentation might be relevant to some aspects of application deployment: