You are on page 1of 19

V4.

1
Instructor Exercises Guide

EXempty

Exercise 13.Package and Deploy a J2EE Application


Estimated Time
00:30

What This Exercise Is About


This exercise takes the library application that has been developed and tested in IBM Rational Application Developer and exports it for deployment on a server.

What You Should Be Able to Do


At the end of the lab, you will be able to: Package an application as an EAR file and export it from the IBM Rational Application Developer environment Install the EAR file on IBM WebSphere Application Server Test the application on a browser

Introduction
The integrated development environment of IBM Rational Application Developer has many advantages, not the least of which is the behind-the-scenes aspect of testing. This means that Run on Server will automatically deploy and install code, open a browser, and run a Web application. However, a completed application will need to be packaged, exported from this environment, and installed on a remote server. This exercise simulates this process. Although the server is the same local server that has been used for testing, it is in fact a stand-alone WebSphere Application Server that can be used outside of the Rational Application Server environment. In this exercise, you will export the Web application (packaged in an EAR file), then use the WebSphere Application Server Administrative console to install and configure it. Finally, you will test it using an external browser.

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-1

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

Required Materials
This exercise requires the database to be set up in a specific way using files that can be found in the <LAB_FILES>\Deploy\imports directory. Make sure you have these files before starting the lab.

Instructor Exercise Overview


It is difficult to create a truly real-life situation when the only environment available is a standalone computer! Before students begin this exercise, draw diagrams on the whiteboard showing how the single environment of Rational Application Developer development becomes the multiple environment of deployment. Here is an example:

All the required steps are simple, and students will have done many of them several times during the week. It is therefore very important to set the scene and explain exactly why they are doing this exercise.

13-2 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

Exercise Instructions
Preface
The following references in the exercise instructions represent directory locations in your workstation: <LAB_FILES>: C:\LabFiles70 <SDP_DIR>: C:\IBM\SDP70

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-3

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

13.1. Prepare the Workspace


If you skipped previous labs, specifically labs 1-4, perform the following instructions: __ 1. Start IBM Rational Application Developer. __ a. In the Workspace Launcher dialog, specify <LAB_FILES>\workspace as the new workspace directory. __ b. Click OK to open the workspace. __ c. Import the <LAB_FILES>\Profile\solution\ProfileSolution.zip project interchange file. If you need assistance, refer to the instructions in the Appendix, Install the Library Application in a New Workspace.

13-4 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

13.2. Reset the Database


In the previous lab, the Library database was populated in a specific way to demonstrate profiling. Now it needs to be set back to its original state. If you skipped the profiling lab, you can skip to section 13.3. __ 2. Ensure that the WebSphere Application Server is stopped. __ a. In the Servers view, right-click WebSphere Application Server v6.1 and select Stop. __ 3. Import new database configuration files to reset the database default value. __ a. In the Project Explorer, right-click LibraryDatabaseSetup and select Import. __ b. Select File System in the Import dialog, then click Next. __ c. In the From Directory field, browse to <LAB_FILES>\Deploy\imports. __ d. Click Select All to select all files in the imports folder. __ e. Select Overwrite existing resources without warning. Also make sure the Into folder is set to LibraryDatabaseSetup.

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-5

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

__ f.

Click Finish.

__ 4. Recreate the database. __ a. In the Project Explorer, expand LibraryDatabaseSetup driver. Java

__ b. Right-click SetUpLibraryDatabase.java and select Run As Application. __ c. The following messages should be shown in the Console view. Drop existing tables SQL Executed with no SQL Executed with no SQL Executed with no SQL Executed with no SQL Executed with no SQL Executed with no (if they exist) errors: errors: errors: errors: errors: errors:

Create the library tables SQL Executed with no errors: SQL Executed with no errors: SQL Executed with no errors: SQL Executed with no errors: SQL Executed with no errors: SQL Executed with no errors: Load the item table A total of 6 records were processed There were 6 rows added without errors There were 0 warnings and 0 errors Load the patron table A total of 6 records were processed There were 6 rows added without errors There were 0 warnings and 0 errors Load the copy table A total of 13 records were processed There were 13 rows added without errors There were 0 warnings and 0 errors Load the onloan table A total of 6 records were processed There were 6 rows added without errors There were 0 warnings and 0 errors

13-6 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

Load the tablemax table A total of 3 records were processed There were 3 rows added without errors There were 0 warnings and 0 errors

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-7

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

13.3. Package the EAR File


__ 5. Export the LibraryEAR project as library.ear file. __ a. In the Project Explorer view, right-click LibraryEAR, and select Prepare for Deployment.

__ b. In the Project Explorer view, right-click LibraryEAR, and select Export file.

EAR

__ c. In the EAR Export dialog, select LibraryEAR as the EAR application, and browse to <LAB_FILES>\Deploy\exports\library.ear for the Destination.

__ d. Click Finish. __ e. You should now be able to locate the library.ear file in the <LAB_FILES>\Deploy\exports directory.

13-8 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

13.4. Start the server and Administrative Console


__ 6. Remove projects from the server. __ a. In the Servers view, expand WebSphere Application Server v6.1, right-click LibraryEAR, and select Remove. __ b. Click OK in the confirmation dialog. __ 7. Start the server. __ a. In the Servers view, right-click WebSphere Application Server V6.1, and select Start. __ b. Switch to the Servers view and wait for the server status to change to Started. __ 8. Start administrative console. __ a. Right-click WebSphere Application Server V6.1 from the Servers view, then select Run administrative console to load the administrative console in a Web browser. __ b. Type admin in the User ID field, and click Log in.

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-9

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

13.5. Install the Enterprise Application


__ 9. Install Library Enterprise Application to the application server (server1). __ a. In the Admin Console, expand Applications in the left navigation, and click Install New Application.

__ b. In the Preparing for the application installation page, select Local file system and click Browse. Navigate to the <LAB_FILES>\deploy\exports directory where the library.ear was saved in the previous step. Select library.ear and click Open. The Local file system field should now contain the path of the EAR file.

__ c. Click Next. __ d. The next page will show Step 1: Select installation options. On the left side menu, notice that there are three steps to complete. You can complete each step

13-10 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

in turn and press Next to navigate to the next step, or you can jump directly to a step by clicking on its link.

__ e. In Step 1, select the check box to enable Pre-compile JSP. This operation takes a little while to complete, but is an excellent option to select when testing. This way you can ensure that all JSPs will compile. In production, this is a way to

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-11

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

reduce the response time for the first request of a JSP page. Change the Application name to LibraryApplication. Click Next.

__ f.

Step 2 will now be displayed. Notice that Step 1 is still listed as a hyperlink, allowing you to return to any previous step. Step 2 allows you to map modules

13-12 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

that are contained in your application. You have only one module, LibraryWeb, which has already been configured to deploy to server1. Click Next.

__ g. Step 3 displays a summary of the configurations set in the previous steps. Verify the information, then click Finish.

__ h. You should see a page headed Installing, and messages will scroll down to indicate the progress of the installation. The application server will step through

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-13

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

the module to performing installation tasks. Look for the following message to confirm that the enterprise application was successfully installed.

13-14 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

13.6. Start the Enterprise Application


Before you can test the application, you must start the LibraryApplication. __ 10. Start the Library enterprise application. __ a. In the Admin Console, expand Applications, and click Enterprise Applications. The page displayed in the workspace lists the enterprise applications installed, and indicates whether they are started or stopped.

__ b. Select the check-box next to LibraryApplication and Click Start. This will attempt to start the LibraryApplication enterprise application. __ c. Once completed, look for a message at the top of the screen indicating that LibraryApplication started successfully.

__ d. Scroll down to the list of enterprise applications table, and you should also see that LibraryApplication has a status of Started. Note If an error is reported, use the command prompt to change to the <SDP_DIR>\runtimes\base_v61\profiles\AppSrv01\logs\server1 directory and display the contents of SystemOut.log. Scroll down to the bottom of the file to see the latest messages. This should provide more information about the error. Verify that you followed all of the above steps correctly, and try restarting the server if you still experience problems.

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-15

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

13.7. Test the Library Application


__ 11. Test the Servlet. __ a. In the J2EE perspective, click the Web browser icon.

__ b. In the Web browser, enter the address http://localhost:9080/Library/List. A list of all the patrons and their on loan items should be displayed.

__ 12. Test the JSP pages. __ a. In the Web browser, specify the address http://localhost:9080/Library/search.jsp.

13-16 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

__ b. Type 4 in Search Phrase, select Patron ID, and click Search.

__ c. The list of items for that patron should be displayed.

__ 13. Test the Struts pages. __ a. Type http://localhost:9080/Library/login.jsp in the browser address to go to a login page. __ b. Type 2 in User ID and vogel in Password, then click Login.

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-17

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

Instructor Exercises Guide

__ c. The following page should show upon a successful login.

__ 14. Test the JSF pages. __ a. Type http://localhost:9080/Library/faces/register.jsp in the browser address to load the Register A New Patron page. __ b. Enter the following information, then click Register. First Name: Jimmy Last Name: World Email: jv@ibm.com Password: donuts

__ c. The registration successful page should now show, with a random ID generated for the patron.

13-18 Developing Web Applications

Copyright IBM Corp. 2004, 2007

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

V4.1
Instructor Exercises Guide

EXempty

END OF LAB

Copyright IBM Corp. 2004, 2007

Exercise 13. Package and Deploy a J2EE Application

13-19

Course materials may not be reproduced in whole or in part without the prior written permission of IBM.

You might also like