Sun GlassFish Enterprise Server v3 Embedded Server Guide

Deploying and Undeploying an Application in an Embedded Enterprise Server

Deploying an application installs the files that comprise the application into Enterprise Server and makes the application ready to run. By default, an application is enabled when it is deployed.

For general information about deploying applications in Enterprise Server, see Sun GlassFish Enterprise Server v3 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 Sun GlassFish Enterprise Server v3 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 Enterprise 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 Sun GlassFish Enterprise Server v3 Application Deployment Guide.

  1. Instantiate the java.io.File class to represent the archive file or directory.

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

  3. 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.

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

    Specify the java.io.File 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 java.io.File;
...
import org.glassfish.api.deployment.*;
...
import org.glassfish.api.embedded.*;
...
    Server.Builder builder = new Server.Builder("test");
    ...
    Server server = builder.build();
    server.createPort(8080);
    server.start();

    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 Enterprise Server. For example, before stopping Enterprise Server, undeploy all applications that are running in Enterprise Server.

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);
...