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.
Instantiate the java.io.File class to represent the archive file or directory.
Invoke the getDeployer method of the Server object to get an instance of the org.glassfish.api.embedded.EmbeddedDeployer class.
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.
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.
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); ...