Sun ONE logo      Previous      Contents      Index      Next     

Sun ONE Application Server 7 Getting Started Guide

Chapter 7
Deploying and Running the Sample Application

Your next step after having defined the JDBC connection pool and resource entries required by the application is to deploy the application.

Although a prebuilt copy of the sample application’s EAR file is included as part of the sample, you will use the Ant facility and the sample's build.xml file to quickly compile the application source code and reassemble the EAR file from scratch. You will then deploy this newly built EAR file to the application server and exercise the application.

This section contains the following topics:


Compile and Reassemble the Application

If you are either sharing your application server installation with other users or your system user ID does not have write permissions to the area in which the application server is installed, you should make a copy of the sample applications in your own directory before proceeding with this section. See "Making Your Own Copy of the Samples". Otherwise, proceed to "Compiling and Reassembling the Application".

This section contains the following topics:

Making Your Own Copy of the Samples

If you are either sharing your application server installation with other users or your system user ID does not have write permissions to the area in which the application server is installed, copy the following directory to a location in which your user ID has write permissions:

install_dir\samples

To use the Ant build facility with the sample in this guide, you must ensure that the com.sun.aas.installRoot property in the following file is set to the installation path of the application server:

personal_samples_dir/samples/common.properties

This property is set automatically when the application server is installed except in the case when the application server is installed as part of a Solaris 9 installation.

In the case of copying the samples from /usr/appserver/samples in a Solaris 9 environment, you need to edit the common.properties file to reflect the following:

com.sun.aas.installRoot=/usr/appserver

Although customization of this property is sufficient to use Ant to the extent that is is demonstrated in this guide, to work with the full capabilities of Ant and the sample applications, you will need to customize additional properties in the common.properties file. After you complete the Getting Started Guide, refer to the “Using Ant with the Samples” section of the sample application documentation for details on customizing the other properties found in the common.properties file.

As you proceed with this guide, replace install_dir/samples/ with the location of your own copy of the sample applications.

Compiling and Reassembling the Application

  1. Ensure that your environment is configured to include the application server's bin directory.
  2. This step was addressed in the section "Setting Up Your Environment".

  3. Using the command line, navigate to the source directory of the jdbc-simple sample application:
  4. cd install_dir\samples\jdbc\simple\src

  5. From the command line, execute the Ant wrapper script asant(.bat) without any arguments to compile the Java source files and assemble the J2EE WAR, EJB JAR and EAR files:
  6. asant


    Tip

    What is asant? The asant utility is simply a wrapper script that calls the Apache Ant main class. A wrapper script is used to first set the appropriate classpath settings associated with the application server environment. For example, the appropriate JDK is set in the environment along with the JAR file containing the custom Ant tasks that are bundled with the application server. If you would like to use your own copy of Ant, review the asant(bat) file to ensure that the same classpath settings are made in your own Ant environment.



    Tip

    What does executing asant do? The asant utility automatically picks up a file name build.xml in the same directory in which asant is executed, much like the make command automatically processes a local Makefile. Like make, Ant supports the notion of a default target. In the case of the sample applications included in the application server, a default target named core results in a complete rebuild of a sample application. Other popular targets are: compile and deploy. See the Sample Applications documentation for more details.


  7. Verify that the EAR file has been created by looking for a file named jdbc-simple.ear located in the following directory:
  8. cd ../assemble/ear

    You should see a file named jdbc-simple.ear in this directory.

    Now that you have successfully assembled the application from scratch, you can use the administrative console to deploy the application.


Deploy the Sample Application

  1. In the administrative console, select and expand the Applications node under the application server instance server1.
  2. Select the folder Enterprise Applications.
  3. Click the Deploy button.
  4. Figure 7-1  Deploying sample application
    This screen shot shows the application server Administration interface in a web browser with the Enterprise Apps pane highlighted and the Deploy button circled.

  5. Click the Browse button to bring up the file browser.
  6. Figure 7-2  Browse to the file
    This screen shot shows the application server Administration interface in a web browser with the Upload Deployment File pane highlighted.

  7. Navigate to the following directory and select the jdbc-simple.ear file that you just assembled:
  8. install_dir\samples\jdbc\simple\assemble\ear\

  9. Click Open to select the file.
  10. Figure 7-3  File upload
    This screen shot shows the File Upload dialog box with jdbc-simple.ear highlighted.

  11. Click OK to proceed to the next step.
  12. Figure 7-4  Upload deployment file
    This screen shot shows the application server Administration interface in a web browser with the Upload Deployment File pane highlighted.

    Before clicking OK to deploy the application, note the Run Verifier and Precompile JSPs check boxes. These options enable you to run a J2EE application verifier as part of the deployment process. (The verifier can also be access through execution of “asant verify” in the sample applications). The Precompile JSP option enables you to have the JSPs files compiled during the deployment process. Although the deployment process will be longer due to the JSP compilation step, the first access to your JSPs will be much faster.

  13. Click OK to deploy the application.
  14. Figure 7-5  jdbc-simple application
    This screen shot shows the application server Administration interface in a web browser with the Deploy Enterprise App pane highlighted.

  15. Once the deployment process completes, the following page is displayed:
  16. Figure 7-6  Completed deployment process
    This screen shot shows the application server Administration interface in a web browser with the Enterprise Applications pane highlighted and the jdbc-simple item highlighted.


    Note

    What happens during deployment? To support formal application deployments, the administrative server must be running. The administrative server receives the deployed application, registers the application in the target server instance's server.xml file and installs the application in the target server instance's application deployment area.

    During initial deployment of an application, the administrative server automatically generates stubs and skeletons for all of the EJBs contained in the application (if EJBs exist). Subsequent redeployment of the same application and EJBs are typically much faster than the initial deployment because the deployment infrastructure senses whether or not the EJBs' interfaces have changed. (EJB stub and skeleton generation account for the majority of time spent during the initial deployment). During a redeployment, for those EJBs whose interfaces have not changed, the stub and skeleton generation step is bypassed. This feature is referred to as “smart redeploy”.

    After deployment of an EAR, you'll find the application expanded in the following location:

    domain_config_dir/domain1/server1/applications/j2ee-apps/jdbc-simple_1

    The trailing _1 represents the number of times this application has been deployed. This number is incremented during each redeployment.

    Web and EJB modules that are deployed individually are expanded under the applications/j2ee-modules directory.


  17. Make the application server instance aware of the newly deployed application by applying the changes:
    1. Select the server1 node.
    2. Click Apply Changes.
    3. Note that a server instance restart is not required in this case.


      Note

      Module deployment: Sun ONE Application Server 7 supports deployment of individual WAR and EJB JAR modules in addition to EAR file deployments. WAR module deployments are especially useful for web only applications. Under the Applications node in the administrative console, there is a Web Apps folder and an EJB Modules folder. Individually deployed modules reside under these folders. Each module is isolated after deployment in the sense that the application server instance uses a distinct classloader sandbox for each EAR-based application and each individually deployed WAR and EJB JAR module.



      Tip

      Deploying from the command line: In addition to deploying applications via the administrative console, you can also use the asadmin utility to deploy applications from the command line. Execute the following command for more information:

      asadmin deploy --help

      Additionally, the application server contains custom Ant tasks that ease the process of deploying applications from Ant build.xml files. All of the samples application build.xml files support the “deploy” target. See the Sample Applications and Using Ant with the Application Server documentation for more information.


      Now that the application is deployed, you will be ready to run it after you first set up your environment to monitor application output in the server log file.


Prepare to Monitor the Sample

Before running the sample, you should prepare to view the output generated by both the sample as well as by the application server runtime. Since by default application output to stdout and stderr is redirected to the application server's event log, the application server provides you with a single place to monitor both the execution of both your server side application and application server infrastructure.

Viewing Application Output and Logs on UNIX

Developers typically use the tail -f command to monitor log files on UNIX:

  1. Navigate to the server1 instance's log directory:
  2. cd domain_config/domain1/server1/logs/

  3. Execute tail on the log file:
  4. tail -f server.log

Proceed to "Using the Administrative Console to View Logs".

Viewing Application Output and Logs on Windows

While you are testing applications on an application server instance, you will likely find it useful to monitor server event log information on the Windows desktop. Such information can include your application's output to stdout and stderr, exceptions and server event messages.

As described in the previous section, display of application server instance event log information on the desktop is enabled by default.

If you would like to disable display of event log data on the desktop, you can use the administrative console to make this change. You can click the Logging tab, then General to access the Create Console setting of an application server instance, which enables you to control whether or not the application server log content for that instance is displayed in a command window on the desktop:

Figure 7-7  Create console

This screen shot shows the application server Administration interface in a web browser with the Logging tab highlighted and the Create console item circled.

Using the Administrative Console to View Logs

You can also use the administrative console to view server instance log files:

  1. Access the administrative console.
  2. Select the server1 node.
  3. Select the Logging tab followed by selecting the View Event Log link.
  4. Figure 7-8  View event log
    This screen shot shows the application server Administration interface in a web browser with the View Error Log pane highlighted.

You can refresh the log view by clicking the OK button.

If you would like to see more than 25 log entries, simply enter a larger number in the “Number of errors to view?” area and click OK to refresh the log display. Try a value of 200 or so to see more log entries.


Note

Viewing HTTP access log: Note the View HTTP Access Log link in the Logging area. Clicking on this link will display the HTTP access log for the server instance. The name of the access log is access. By default, the access log file is located in the same directory as the server event log:

domain_config_dir/domain1/server1/logs/


Now that you are ready to monitor the server log file, the next step is to start the database prior to running the application.


Run the Application

To run the sample application, perform the following steps:

  1. First ensure that you are monitoring the server event log file for application output.
  2. From a browser, access the following URL, enter your name, and click Process.
  3. http://localhost:port/jdbc-simple

    As you click on the Process button, note the application output written to the server event log file. Also note that there is a discernible delay while the application server compiles the initial JSP source file for the first time.


    Note

    Application output in server event log: When your application writes information to stdout and/or stderr, by default, this information is recorded in the server instance’s event log as INFO-level messages with the message ID CORE3282 (stdout) and CORE3283 (stderr). While running the jdbc-simple sample, a number of application generated messages are written the server event log. The following excerpt provides a snapshot of some of these messages:

    For example:

    INFO: CORE3282: stdout: GreeterDBServlet is executing...

    INFO: CORE3282: stdout: Retrieving JNDI initial context...

    INFO: CORE3282: stdout: - Retrieved initial context successfully

    INFO: CORE3282: stdout: Looking up dbGreeter bean home interface...

    INFO: CORE3282: stdout: - Looking up: java:comp/env/ejb/jdbc-simple

    INFO: CORE3282: stdout: - Looked up the EJB successfully


  4. Once the greeting is displayed, click the link provided to view a log of all greetings generated to date.
  5. Again, there will be a delay as the second JSP source file is compiled.

  6. Run the sample again to see how quickly it responds the second time you do so.
  7. Since the JSP files are already compiled, the second invocation is much faster than the initial run.


Troubleshooting

The most common problems when attempting to run this sample application are described in the following table.

Table 7-1  Troubleshooting

Symptom

Probable cause

Solution

Connection failure when attempting to access first page.

Application server not started.

Wrong port specified in URL.

Ensure that the application server has been started.

Determine the correct HTTP server port number.

Se "Starting and Stopping the Application Server" for more details.

Greeting is returned, but log of previous greetings displays 0 greetings.

Failed JNDI lookup due to jdbc/jdbc-simple not being defined.

Failed JDBC connection attempt.

Database not started.

Ensure that JDBC resource is defined correctly.

Ensure that JDBC connection pool properties match those that are specified in the instructions.

See "Start the PointBase Server Database".

404 error when accessing main page.

Application not deployed.

See "Deploy the Sample Application".

When troubleshooting problems, it is very important that you monitor the application server log file. You may also find it useful to review the HTTP access log file to verify that HTTP requests are arriving at the application server as expected.

Proceed to Chapter 8, "Modifying the Sample Application" to learn how the application server supports dynamic redeployment and reloading.



Previous      Contents      Index      Next     


Copyright 2003 Sun Microsystems, Inc. All rights reserved.