Sun Microsystems Logo

 

 
 

Sun[tm] ONE Application Server 7
Deploying and Running the Sample Application
PREV START NEXT

 

Your next step after having defined the JDBC[tm] 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.

  1. Compile and Reassemble the Application
  2. Deploy the Application
  3. Prepare to Monitor the Application
  4. Run the Application

1. 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. If you are using the application server that was installed as part of a Solaris 9 installation, it is recommended that you make your own copy of the the samples.

If you are not sharing the application server installation with other users, proceed to Compiling and Reassembling the Application.

Making Your Own Copy of the Samples

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

The com.sun.aas.installRoot 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 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 Creating Your Own Sample Environment 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.

This step was addressed in the section Setting Up Your Environment.

2. Using the command line, navigate to the source directory of the jdbc-simple sample application:

    cd <install_dir>\samples\jdbc\simple\src

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

    asant

Informational Note IconWhat 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.


Informational Note IconWhat does executing asant do? The asant utility automatically picks up a file name build.xml in the same directory as 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.

4. Verify that the EAR file has been created by looking for a file named jdbc-simple.ear located in the following directory:

    cd ../assemble/ear

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

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

2. Deploy the Application

1. In the administrative console, select and expand the Applications node under the application server instance "server1".

2. Select the folder Enterprise Apps.

3. Click the Deploy... button.

    Deploy Application Screenshot

4. Click the Browse... button to bring up the file browser.

    Select Application Screenshot

5. Navigate to the following directory and select the jdbc-simple.ear file that you just assembled.

    <install_dir>\samples\jdbc\simple\assemble\ear\

6. Click Open to select file.

    File Upload Screenshot

7. Click OK to proceed to the next step.

    Application Specified Screenshot

8. Before clicking OK to deploy the application, note the Run Verifier and Precompile JSPs check boxes. These options enable you to run a J2EE[tm] 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 JPS 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.

Click OK to deploy the application.

    Deployment Options Screenshot

9. Once the deployment process completes, the following page is displayed:

    Application Deployed Screenshot

    Informational Note IconWhat 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.

10. Make the application server instance aware of the newly deployed application by applying the changes.

10a. Select the "server1" node.

10b. Click the Apply Changes button. Note that a server instance restart is not required in this case.

Informational Note IconModule 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.


Informational Note IconDeploying 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 are ready to ensure that you are monitoring the application server log file prior to running the application.

3. Prepare to Monitor the Application

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 Output and Logs on UNIX
  » Viewing Output and Logs on Windows
  » Using the Administrative Console to View Event Logs

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 Event 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 you observed 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. The Create Console setting under the Logging->General area of an application server instance enables you to control whether or not the application server log content for that instance is displayed in a command window on the desktop.

    Create Console Option Screenshot

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.
View Event Log Screenshot

You can refresh the log view by clicking on 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.

Informational Note IconViewing 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 file name of the access log is access. By default, the HTTP 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.

4. 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 on Process.

    http://localhost:<port>/jdbc-simple

As you click 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.

Informational Note IconApplication 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 with the message ID CORE3282 (stdout) and CORE3283 (stderr). Information written to stdout is classified as INFO severity level while information written to stderr is classified as WARNING severity level. 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:

...
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
...

3. Once the greeting is displayed, click the link provided to view a log of all greetings generated to date.

Again, there will be a delay as the second JSP source file is compiled.

4. Run the sample again to see how quickly it responds the second time through.

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:

Sympton 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.

See the section 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.

Start the PointBase Server.

404 error when accesing main page. Application not deployed. Deploy the 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 Modifying the Sample Application to learn how the application server supports dynamic redeployment and reloading.

PREV START NEXT