Sun ONE Application Server 7 Getting Started Guide |
Chapter 7
Deploying and Running the Sample ApplicationYour 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 ApplicationIf 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
- 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".
- Using the command line, navigate to the source directory of the jdbc-simple sample application:
cd install_dir\samples\jdbc\simple\src
- 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:
asant
- 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 assembled the application from scratch, you can use the administrative console to deploy the application.
Deploy the Sample Application
- In the administrative console, select and expand the Applications node under the application server instance server1.
- Select the folder Enterprise Applications.
- Click the Deploy button.
Figure 7-1 Deploying sample application
- Click the Browse button to bring up the file browser.
Figure 7-2 Browse to the file
- Navigate to the following directory and select the jdbc-simple.ear file that you just assembled:
install_dir\samples\jdbc\simple\assemble\ear\
- Click Open to select the file.
Figure 7-3 File upload
- Click OK to proceed to the next step.
Figure 7-4 Upload deployment file
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.
- Click OK to deploy the application.
Figure 7-5 jdbc-simple application
- Once the deployment process completes, the following page is displayed:
Figure 7-6 Completed deployment process
- Make the application server instance aware of the newly deployed application by applying the changes:
- Select the server1 node.
- Click Apply Changes.
Note that a server instance restart is not required in this case.
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 SampleBefore 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:
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
Using the Administrative Console to View Logs
You can also use the administrative console to view server instance log files:
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.
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 ApplicationTo run the sample application, perform the following steps:
- First ensure that you are monitoring the server event log file for application output.
- From a browser, access the following URL, enter your name, and click Process.
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.
- 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.
- Run the sample again to see how quickly it responds the second time you do so.
Since the JSP files are already compiled, the second invocation is much faster than the initial run.
TroubleshootingThe 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.
404 error when accessing main page.
Application not deployed.
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.