This section provides information for packaging and deploying applications in the Application Server software.
This section describes two techniques for packaging and deploying applications:
For more information, see “Getting Started with Web Applications” inThe J2EE 1.4 Tutorial.
The deploytool utility is recommended for configuring complex JavaTM 2 Platform, Enterprise Edition (J2EETM platform) applications that require security controls, context parameters, enterprise beans, property-group settings (for HTML templates), or database connections.
The deploytool utility lets you:
Create XML deployment descriptors without manually editing XML files.
Package the classes and web content for a J2EE application into a Java archive (JAR), web application archive (WAR) or enterprise archive (EAR) file.
Edit an existing archive file to modify its contents.
Deploy a packaged application onto the Sun Java System Application Server software, or onto other application servers.
The install_dir/samples/quickstart/ directory contains the files used in the Hello World application.
The web subdirectory contains the index.jsp and response.jsp files and the images directory, which contains the duke.waving.gif file.
The web/WEB-INF subdirectory contains the sun-web.xml and web.xml files.
The src/conf subdirectory contains the LocalStrings.properties file.
The Hello World application contains two JSPTM pages and the two files that they reference.
Begin by starting deploytool using the instructions below. Solaris and Linux steps are in the first column, and Windows steps are in the second column:
From the install_dir/bin directory, start the tool:
From the Start menu, choose Programs ⇒ Sun Microsystems ⇒ Application Server PE ⇒ Deploytool.
When deploytool starts, it looks like this:
The tree structure in the pane at the left shows currently active files. It also indicates that the admin server is available to carry out deployment operations at its assigned port number.
In this section, you practice packaging the Hello World application using deploytool
Select File ⇒ New ⇒ Web Component.
The wizard’s Introduction appears.
Click Next to display the Wizard’s main screen.
You will create a new stand-alone WAR module, so accept the default selection for the WAR Location panel.
With the hello.war file open, the default WAR File location is shown as install_dir/samples/quickstart/. With no WAR files open, the field is blank. Either way, click the Browse button to specify the name of the WAR file to create. (“WAR File” must specify the full path to a WAR file.)
If you are not already there, navigate to install_dir/samples/quickstart.
Enter the filename as hello2 and click Create Module File to create the WAR file and return to the Wizard.
The Wizard now shows WAR Name as hello2. WAR Display Name is the title that appears in administration utilities like deploytool and the Admin Console. It defaults to the same name as the WAR file in the Wizard, but it can be different.
In Context Root enter /hello2 to define the URL for the web application as http://server:port/hello2. In most production systems, of course, the Application Server software uses a default port, so the port number is not part of the URL that users type.
Click Edit Contents to add the files that make up the application.
The Edit Content dialog appears.
You can press the Control key and click multiple files.
Navigate to install_dir/samples/quickstart.
You can use the drop-down list of shortcuts.
In the lower panel, “Contents of hello2,” click the WEB-INF node to expand it.
In the upper panel, “Available Files,” under src/conf, click the file LocalStrings.properties and drag and drop it on the WEB-INF/classes directory in the lower panel.
The LocalStrings.properties file is added under the WEB-INF/classes directory.
In the web/ directory, select the images/ directory and the index.jsp and response.jsp files.
Click Add. The dialog shows that the selected files have been added.
Click OK to return to the Wizard’s WAR File definition window.
Click Next to complete the process of defining the WAR file.
The Choose Component Type dialog appears.
Select JSP Page and click Next.
The Component General Properties screen appears.
From the drop-down list for “JSP Filename,” select index.jsp.
This selection populates the other fields with default values based on the name.
Click Next and read the notes about the next steps you can take.
Click Finish to end the Wizard and return to the deploytool screen.
You have just packaged a simple application. In The J2EE 1.4 Tutorial, you can learn how to package more complex applications, but the general outline of the process is similar. Now that it is packaged, deploying the application is a simple operation. You will do that next.
Once the application is packaged, you can deploy it using deploytool.
The deploytool utility now shows the hello2 application, and has it selected.
From the toolbar, choose the Tools option and then Deploy.
The security dialog appears.
Supply the admin user name and password. (If you chose “Don’t prompt for username” during the installation, these fields are already filled in.)
The server now starts loading the application. A dialog appears to inform you of the server’s progress, so that you know when the deployment operation has completed. Click Close to close the dialog.
Verify that the application is running by going to this URL: http://localhost:8080/hello2.
You should now see the hello application’s first page, which provides a greeting from Duke, asking you to fill in your name.
Type in your name and click Submit.
You should now see the customized response, giving you a personal Hello.
You can deploy an application directly from a development directory, if the appropriate directory hierarchy and deployment descriptors have been created. Because the process is complex for non-trivial applications, it is a procedure that is recommended only for advanced users, or simple applications. But when it is feasible to do so, deploying directly from a directory, instead of using the deploytool utility, can speed up the development cycle.
The process can be performed interactively by using the Admin Console, or by using asadmin deploydir from the command line or in a script. The steps for the command line are presented here, since most developers want to automate the procedure in command scripts.
In the install_dir/samples/quickstart/ directory, create a new directory called build/.
Unzip the contents of the hello.war file into the build/ directory.
Preserve the directory structure of the hello.war file when you unzip it. It is a template for the kind of file structure you need to deploy directly from a directory.
If you already have an application hello deployed, undeploy it now using the command asadmin undeploy hello.
Issue the following command to deploy the application:
asadmin deploydir install_dir/samples/quickstart/build
Specify the full path to the build/ directory.
If you did not install the Application Server with the “Don’t prompt” option, also specify --user username --password password, where username is the admin user name and password is the admin password.
Verify that this message appears to confirm that the redeployment succeeded:
Command deploydir executed successfully.
Verify that the application is running by going to this URL: http://localhost:8080/hello.