Application deployment is a dynamic process, which means that deployed applications and modules become available without requiring you to restart the server instance. Dynamic deployment can be useful in production environments to bring new applications and modules online easily. If you do restart the server, all deployed components are still deployed and available.
The following topics are addressed here:
Instructions for accomplishing these tasks by using the Administration Console are contained in the Administration Console online help.
Use the deploy subcommand in remote mode to deploy an assembled application or module to Enterprise Server. If an error occurs during deployment, the application or module is not deployed. These failures prevent a partial deployment that could leave the server in an inconsistent state.
If the component is already deployed or already exists, you can forcefully redeploy if you set the --force option of the deploy subcommand to true. See Example 2–9. The redeploy subcommand also accomplishes this. You can see the status of a component by using the show-component-status(1) subcommand.
The Java EE 6 specification defines the portable application-name, which allows you to specify an application name in the application.xml file. For example:
<application-name>xyz</application-name> |
This name is used before the archive name to derive the default application registration name. The application will be deployed under xyz if the application.xml file defines application-name as xyz. The user-specified name has the highest precedence. If no application-name is specified in the application.xml file, the application is deployed using the archive name (minus suffix) as the application registration name.
Ensure that the server is running.
Remote commands require a running server.
(Optional) List deployed components by using the list-components(1) subcommand.
Deploy the application or module by using the deploy(1) subcommand.
Information about the options and properties of the subcommand is included in this help page.
(Optional) If needed, fix issues and rerun the deploy subcommand.
This example deploys newApp.ear to the default server, server.
asadmin> asadmin> deploy Cart.ear Application deployed successfully with name Cart. Command deploy executed successfully |
This example deploys a connector modules that is packaged in an RAR file.
asadmin> deploy jdbcra.rar Application deployed successfully with name jdbcra. Command deploy executed successfully |
You can also view the full syntax and options of the subcommand by typing asadmin help deploy at the command line.
There are a number of commands that can be used to list deployed applications or modules and their subcomponents. Use the commands in this section in remote mode.
Ensure that the server is running.
Remote commands require a running server.
List the desired components by using the list-applications(1) subcommand, the list-components(1) subcommand , or the list-sub-components(1)command.
Information about these commands is included in these help pages.
Show the status of a deployed component by using the show-component-status(1).
The list-applications subcommand lists all deployed Java EE applications or modules. If the --type option is not specified, all components are listed. This example lists deployed applications.
asadmin> list-applications --type web hellojsp <web> Command list-applications executed successfully |
The list-components subcommand lists the deployed Java EE components. If the --type option is not specified, all components are listed. This example lists the components of the deployed cciblackbox-tx.rar.
asadmin> list-components --type connector cciblackbox-tx <connector> Command list-components executed successfully |
The list-sub-components subcommand lists EJBs or servlets in a deployed module or in a module of the deployed application. If a module is not identified, all modules are listed. The --appname option functions only when the given module is standalone. To display a specific module in an application, you must specify the module name and the --appname option. This example gets the subcomponents of application MEjbApp within module mejb.jar.
asadmin> list-sub-components --appname MEjbApp mejb.jar MEJBBean <StatelessSessionBean> Command list-sub-components executed successfully |
The show-component-status subcommand gets the status (enabled or disabled) of the deployed component. This example gets the status of the MEjbApp component.
asadmin show-component-status MEjbApp Status of MEjbApp is enabled Command show-component-status executed successfully |
Use the redeploy subcommand in remote mode to overwrite a previously–deployed application or module. You can also accomplish this task by using the --force option of the deploy subcommand. Whenever a redeployment is done, the sessions in transit at that time become invalid unless you use the keepSessions=true property of the redeploy subcommand.
You must remove a preconfigured resource before it can be updated.
Ensure that the server is running.
Remote commands require a running server.
Redeploy an application or module by using the redeploy(1) subcommand or the deploy(1) subcommand with the --force option.
Information about the options and properties of these commands is included in these help page.
This example redeploys the hello web application. In a production environment, you usually want to retain sessions. If you use the keepSessions property, active sessions of the application are retained and restored when redeployment is complete.
asadmin> redeploy --name hello --properties keepSessions=true hello.war Application deployed successfully with name hello. Command redeploy executed successfully. |
Keep Sessions is a checkbox option when you redeploy using the Administration Console. For instructions, see the Administration Console online help.
This example redeploys the hello web application, which was originally deployed from the hellodir directory. The path is retrieved from the domain.xml file.
asadmin>redeploy --name hellodir Application deployed successfully with name hellodir. Command redeploy executed successfully. |
The --force option is set to false by default. This example redeploys newApp.ear even if has been deployed or already exists.
asadmin> deploy --force=true newApp.ear Application deployed successfully with name newApp. Command deploy executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help redeploy at the command line.
Use the disable subcommand in remote mode to immediately deactivate a deployed application or module without removing it from the server. Disabling a component makes the component inaccessible to clients. However, the component is not overwritten or uninstalled, and can be enabled by using the asadmin enable subcommand.
By default, a deployed application or module is enabled.
Ensure that the server is running.
Remote commands require a running server.
Obtain the exact name of the application or module that you are disabling.
To list deployed applications or modules, use the list-applications(1) subcommand. If you do not specify a type, all deployed applications and modules are listed. For example, valid types can be web, ejb, connector, application, jruby, and webservice.
To see the status of deployed components, use the show-component-status(1) subcommand.
Deactivate the application or module by using the disable(1) subcommand.
Information about the options and properties of the subcommand is included in this help page.
This example lists all deployed web applications.
asadmin> list-applications --type web hellojsp <web> Command list-applications executed successfully. |
This example disables the hellojsp application.
asadmin> disable hellojsp Command disable executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help disable at the command line.
By default, a deployed application or module is enabled, which means that it is runnable and can be accessed by clients if it has been deployed to an accessible server instance. Use the enable subcommand in remote mode to enable an application or module that has been disabled.
Ensure that the server is running.
Remote commands require a running server.
Enable the application or module by using the enable(1) subcommand.
If the component has not been deployed, an error message is displayed. If the component is already enabled, it is re-enabled. To see the status of deployed components, use the show-component-status(1) subcommand.
Information about the options and properties of the subcommand is included in this help page.
This example enables the sampleApp application.
asadmin> enable sampleApp Command enable executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help enable at the command line.
Use the undeploy subcommand in remote mode to uninstall a deployed application or module and remove it from the repository. To reinstate the component, you must deploy the component again using the deploy subcommand.
Ensure that the server is running.
Remote commands require a running server.
Obtain the exact name of the application or module you are undeploying.
To list deployed applications or modules, use the list-applications(1) subcommand. If you do not specify a type, all deployed applications and modules are listed. For example, valid types can be web, ejb, connector, application, jruby, and webservice.
To see the status of deployed components, use the show-component-status(1) subcommand.
Undeploy the application or module by using the undeploy(1) subcommand.
Information about the options and properties of the subcommand is included in this help page.
This example lists all applications of type web.
asadmin> list-applications --type web hellojsp <web> Command list-applications executed successfully. |
This example uninstalls the hellojsp application.
asadmin> undeploy hellojsp hellojsp <web> Command undeploy executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help undeploy at the command line.
Dynamic reloading enables you to change the code or deployment descriptors of an application or module without needing to perform an explicit redeployment. Instead, you can copy the changed class files or descriptors into the deployment directory for the application or module. The server checks for changes periodically and automatically redeploys the changes if the timestamp of the .reload file in the root directory for the application or module has changed.
Dynamic reloading is enabled by default, and is available only on the default server instance.
Create an empty file named .reload at the root of the deployed application or module.
domain-dir/applications/module-name/.reload
Deployment directories might change between Enterprise Server releases.
Update the timestamp of the .reload file to load the changes.
In UNIX: touch .reload
Another method for updating an application or module is to use the sun-appserv-update task with the Enterprise Server Ant tasks. See Chapter 3, Using Ant with Enterprise Server, in Sun GlassFish Enterprise Server v3 Application Development Guide.
This task is best suited for use in a development environment.
Automatic deployment involves copying an archive file into a special autodeploy directory where the archive is automatically deployed by Enterprise Server at predefined intervals. This method is useful in a development environment because it allows new code to be tested quickly. Automatic deployment is enabled by default.
(Optional) Use the set(1) subcommand to adjust the autodeployment interval.
This sets the interval at which applications and modules are checked for code changes and dynamically reloaded. The default is 2.
(Optional) Use the set(1) subcommand to enable JSP precompilation.
Copy your archive file to the autodeploy directory.
The default location is domain-dir/autodeploy. The application will be deployed at the next interval.
To undeploy an automatically deployed application or module, remove its archive file from the autodeploy directory.
Deployment directories might change between Enterprise Server releases.
This example sets the autodeployment inverval to 3 seconds (default is 2).
asadmin> set server.admin-service.das-config.autodeploy-polling-interval-in-seconds=3 Command set executed successfully. |
This example enables JSP precompilation (default is false).
asadmin> set server.admin-service.das-config.autodeploy-jsp-precompilation-enabled=true Command set executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help set at the command line.
In the deployment plan for an EAR file, the sun-application.xml file is located at the root. The deployment descriptor for each module is stored according to this syntax: module-name.sun-dd-name, where the sun-dd-name depends on the module type. If a module contains a CMP mappings file, the file is named module-name.sun-cmp-mappings.xml. A .dbschema file is stored at the root level. Each / (forward slash) is replaced by a # (pound sign).
Ensure that the server is running.
Remote commands require a running server.
Deploy the application or module by using the deploy(1) subcommand with the --deploymentplan option.
Deployment directories might change between Enterprise Server releases.
This example deploys the application in the myrostapp.ear file according to the plan specified by the mydeployplan.jar file.
asadmin>deploy --deploymentplan mydeployplan.jar myrostapp.ear Application deployed successfully with name myrostapp. Command deploy executed successfully. |
This listing shows the structure of the deployment plan JAR file for an EAR file.
$ jar -tvf mydeployplan.jar 420 Thu Mar 13 15:37:48 PST 2003 sun-application.xml 370 Thu Mar 13 15:37:48 PST 2003 RosterClient.war.sun-web.xml 418 Thu Mar 13 15:37:48 PST 2003 roster-ac.jar.sun-application-client.xml 1281 Thu Mar 13 15:37:48 PST 2003 roster-ejb.jar.sun-ejb-jar.xml 2317 Thu Mar 13 15:37:48 PST 2003 team-ejb.jar.sun-ejb-jar.xml 3432 Thu Mar 13 15:37:48 PST 2003 team-ejb.jar.sun-cmp-mappings.xml 84805 Thu Mar 13 15:37:48 PST 2003 team-ejb.jar.RosterSchema.dbschema |
In the deployment plan for a web module, the deployment descriptor that is specific to Enterprise Server is at the root level. If a standalone EJB module contains a CMP bean, the deployment plan includes the sun-cmp-mappings.xml and .dbschema files at the root level. In the following listing, the deployment plan describes a CMP bean:
$ jar r -tvf myotherplan.jar 3603 Thu Mar 13 15:24:20 PST 2003 sun-ejb-jar.xml 3432 Thu Mar 13 15:24:20 PST 2003 sun-cmp-mappings.xml 84805 Thu Mar 13 15:24:20 PST 2003 RosterSchema.dbschema |
The deployment plan is part of the implementation of JSR 88. For more information about JSR 88, see JSR 88 Naming and the JSR 88 page at http://jcp.org/en/jsr/detail?id=88.
This task is best suited for use in a development environment.
An expanded directory, also known as an exploded directory, contains an unassembled (unpackaged) application or module. To deploy a directory format instead of an archive, use the asadmin deploy subcommand in remote mode and specify a path to a directory instead of to an archive file. The contents of the directory must be the same as the contents of a corresponding archive file. The directories that hold modules must be named with suffixes that identify the type of archive that the structure is based on, such as _jar or _war.
You can change deployment descriptor files directly in the expanded directory.
If your environment is configured to use dynamic reloading, you can also dynamically reload applications or modules that are deployed from the directory. For instructions, see To Reload Changes to Applications or Modules Dynamically.
The directory must be accessible to the machine on which Enterprise Server runs.
On Windows, if you are deploying a directory on a mapped drive, you must be running Enterprise Server as the same user to which the mapped drive is assigned. This enables Enterprise Server to access the directory.
Ensure that the server is running.
Remote commands require a running server.
Verify that the expanded directory contents match the archive file.
For information about the required directory contents, see the appropriate specifications.
Deploy the directory by using the deploy(1) subcommand and specifying the path to the expanded directory.
Deployment directories might change between Enterprise Server releases.
This example deploys the expanded directory for the hello application. The path name is stored in the domain configuration file (domain.xml).
asadmin> deploy --name hello Application deployed successfully with name hello. Command deploy executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help deploy at the command line.