Oracle GlassFish Server 3.0.1 Embedded Server 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);