Oracle GlassFish Server 3.0.1 Embedded Server Guide

Deploying and Undeploying an Application in an Embedded GlassFish Server

Deploying an application installs the files that comprise the application into Embedded GlassFish Server and makes the application ready to run. By default, an application is enabled when it is deployed. You can perform operations such as:

For general information about deploying applications in GlassFish Server, see Oracle GlassFish Server 3.0.1 Application Deployment Guide.

ProcedureTo Deploy an Application From an Archive File or a Directory

An archive file contains the resources, deployment descriptor, and classes of an application. The content of the file must be organized in the directory structure that the Java EE specifications define for the type of archive that the file contains. For more information, see Chapter 2, Deploying Applications, in Oracle GlassFish Server 3.0.1 Application Deployment Guide.

Deploying an application from a directory enables you to deploy an application without the need to package the application in an archive file. The contents of the directory must match the contents of the expanded Java EE archive file as laid out by the GlassFish Server. The directory must be accessible to the machine on which the deploying application runs. For more information about the requirements for deploying an application from a directory, see To Deploy an Application or Module in a Directory Format in Oracle GlassFish Server 3.0.1 Application Deployment Guide.

  1. Invoke the addContainer method of the Server object to get an instance of the org.glassfish.api.embedded.ContainerBuilder class.

    Instantiate ContainerBuilder.Type.web, ContainerBuilder.Type.ejb, or ContainerBuilder.Type.all.

  2. Instantiate the class to represent the archive file or directory.

  3. Invoke the getDeployer method of the Server object to get an instance of the org.glassfish.api.embedded.EmbeddedDeployer class.

  4. Instantiate a org.glassfish.api.deployment.DeployCommandParameters class.

    To use the default parameter settings, instantiate an empty DeployCommandParameters class. For information about the fields in this class that you can set, see the descriptions of the equivalent deploy(1) command parameters.

  5. Invoke the deploy(File archive, DeployCommandParameters params) method of the instance of the EmbeddedDeployer object.

    Specify the and DeployCommandParameters class instances you created previously as the method parameters.

Example 6 Deploying an Application From an Archive File

This example shows code for deploying an application from the archive file c:\samples\simple.war and setting the contextroot parameter of the DeployCommandParameters class. This example also includes the code from Example 1 for creating Server.Builder and Server objects.

import org.glassfish.api.deployment.*;
import org.glassfish.api.embedded.*;
    Server.Builder builder = new Server.Builder("test");
    Server server =;

    File war = new File("c:\\samples\\simple.war");
    EmbeddedDeployer deployer = server.getDeployer();
    DeployCommandParameters params = new DeployCommandParameters();
    params.contextroot = "simple";
    deployer.deploy(war, params);

Undeploying an Application

Undeploy an application when the application is no longer required to run in GlassFish Server. For example, before stopping GlassFish Server, undeploy all applications that are running in GlassFish Server.

Note –

If you reference a nonembedded GlassFish Server installation using the glassfish-embedded-static-shell.jar file and do not undeploy your applications in the same server life cycle in which you deployed them, expanded archives for these applications remain under the domain-dir/applications directory.

To undeploy an application, invoke the undeploy method of an existing EmbeddedDeployer object. In the method invocation, pass the name of the application and the name of its DeployCommandParameters class as parameters. Both are specified when the application is deployed.

To undeploy all deployed applications, invoke the undeployAll method of an existing EmbeddedDeployer object. This method takes no parameters.

Example 7 Undeploying an Application

This example shows code for undeploying the application that was deployed in Example 6.

import org.glassfish.api.deployment.*;
import org.glassfish.api.embedded.*;
    deployer.undeploy(war, params);