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.
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.
Instantiate ContainerBuilder.Type.web, ContainerBuilder.Type.ejb, or ContainerBuilder.Type.all.
Instantiate the java.io.File class to represent the archive file or directory.
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.
Specify the java.io.File and DeployCommandParameters class instances you created previously as the method parameters.
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.addContainer(ContainerBuilder.Type.web); 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); ...
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.
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.
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); ...