RAD v7, Programming Guide

1390
ibm.com/redbooks Rational Application Developer V7 Programming Guide Ueli Wahli Henry Cui Craig Fleming Maan Mehta Marco Rohr Pinar Ugurlu Patrick Gan Celso Gonzalez Daniel M. Farrell Andreas Heerdegen Develop Java, Web, XML, database, EJB, Struts, JSF, SDO, EGL, Web services, and portal applications Test, debug, and profile with built-in and remote servers Deploy applications to WebSphere Application Server and WebSphere Portal

Transcript of RAD v7, Programming Guide

Front cover

Rational Application Developer V7 Programming GuideDevelop Java, Web, XML, database, EJB, Struts, JSF, SDO, EGL, Web services, and portal applications Test, debug, and profile with built-in and remote servers Deploy applications to WebSphere Application Server and WebSphere Portal

Ueli Wahli Henry Cui Craig Fleming Maan Mehta Marco Rohr Pinar Ugurlu Patrick Gan Celso Gonzalez Daniel M. Farrell Andreas Heerdegen

ibm.com/redbooks

International Technical Support Organization Rational Application Developer V7 Programming Guide December 2007

SG24-7501-00

Note: Before using this information and the product it supports, read the information in Notices on page xxv.

First Edition (December 2007) This edition applies to Version 7.0 of IBM Rational Application Developer for WebSphere Software.

Copyright International Business Machines Corporation 2007. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

ContentsNotices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvii The team that wrote this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii Become a published author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi Comments welcome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxxii Summary of changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii December 2007, First Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii Part 1. Introduction to Rational Application Developer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 IBM Rational Software Delivery Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Version 7 terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Application development challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Key themes of Version 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Product packaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Rational Developer supported platforms and databases . . . . . . . . . . . . . . . 9 Application Developer V7 product packaging . . . . . . . . . . . . . . . . . . . . . . . 10 Product features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Summary of new features in Version 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Specification versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Eclipse and IBM Rational Software Delivery Platform . . . . . . . . . . . . . . . . . . 16 Eclipse Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Eclipse Software Developer Kit (SDK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Test server environments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Installation and licensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Updates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Uninstall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Migration and coexistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Migration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Compatibility with previous versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Migration considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Copyright IBM Corp. 2007. All rights reserved.

iii

Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Sample code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Chapter 2. Programming technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Desktop applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Simple desktop applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Database access. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Graphical user interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Extensible Markup Language (XML) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Static Web sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Hypertext Transfer Protocol (HTTP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 HyperText Markup Language (HTML) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Dynamic Web applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Simple Web applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Struts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 JavaServer Faces (JSF) and Service Data Objects (SDO) . . . . . . . . . . . . 49 AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Portal applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Enterprise JavaBeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Different types of EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Other EJB features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Requirements for the development environment . . . . . . . . . . . . . . . . . . . . 59 J2EE Application Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Application Programming Interfaces (APIs) . . . . . . . . . . . . . . . . . . . . . . . . 61 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Requirements for the development environment . . . . . . . . . . . . . . . . . . . . 63 Web services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Web services in Java EE V1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Messaging systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Java Message Service (JMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Message-driven EJBs (MDBs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Requirements for the development environment . . . . . . . . . . . . . . . . . . . . 70 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Chapter 3. Workbench setup and preferences . . . . . . . . . . . . . . . . . . . . . . 73 Workbench basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Workspace basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Application Developer logging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Automatic builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

iv

Rational Application Developer V7 Programming Guide

Manual builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 File associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Local history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Perspectives preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Web Browser preferences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Internet preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Java development preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Java classpath variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Appearance of Java elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Code style and formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Java editor settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Compiler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Installed JREs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Chapter 4. Perspectives, views, and editors. . . . . . . . . . . . . . . . . . . . . . . 117 Integrated development environment (IDE) . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Perspective layout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Switching perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Specifying the default perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Organizing and customizing perspectives. . . . . . . . . . . . . . . . . . . . . . . . . 122 Application Developer Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Available perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Crystal Reports perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 CVS Repository Exploring perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Data perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Debug perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Generic Log Adapter perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 J2EE perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Java perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Java Browsing perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Java Type Hierarchy perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Plug-in Development perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Profiling and Logging perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Report Design perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Resource perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Rule Builder perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Team Synchronizing perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Test perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

Contents

v

Web perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Progress view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Chapter 5. Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 J2EE architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 EAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 WAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 EJB JAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 J2EE Application Client JAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 RAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Project basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Deleting projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Project interchange file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Closing projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Rational Application Developer projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Application Developer J2EE projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Creating a new project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Project properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Rational Application Developer samples . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Samples gallery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Example Projects wizard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Part 2. Develop applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Chapter 6. RUP and UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Rational Unified Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Process Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Process Advisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Process preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Constructing and visualizing applications with UML. . . . . . . . . . . . . . . . . . . 181 Unified Modeling Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Working with UML class diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Creating class diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Creating, editing, and viewing Java elements in UML class diagrams . . . 187 Creating, editing, and viewing EJBs in UML class diagrams . . . . . . . . . . 190 Creating, editing, and viewing WSDL elements in UML class diagrams. . 198 Class diagram preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Exploring relationships in applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Browse diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Topic diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

vi

Rational Application Developer V7 Programming Guide

Describing interactions with UML sequence diagrams. . . . . . . . . . . . . . . . . 213 Creating sequence diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Creating lifelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Creating messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Creating combined fragments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Creating references to external diagrams . . . . . . . . . . . . . . . . . . . . . . . . . 221 Exploring Java methods by using Static Method Sequence diagrams . . . 222 Sequence diagram preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 More information on RUP and UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Chapter 7. Develop Java applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Java perspectives, views, and editor overview . . . . . . . . . . . . . . . . . . . . . . . 228 Java perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Package Explorer view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Hierarchy view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Outline view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Problems view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 Declaration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Console view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Call Hierarchy view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Analysis Results view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Java Browsing perspective. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Java Type Hierarchy perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Developing the ITSO Bank application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 ITSO Bank application overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Interfaces and classes overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Packaging structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Class diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 ITSO Bank application step-by-step development guide . . . . . . . . . . . . . . . 239 Creating a Java project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Creating a UML class diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 Creating Java packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Creating Java interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Creating Java classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Creating Java attributes (fields) and getter and setter methods . . . . . . . . 250 Adding method declarations to an interface . . . . . . . . . . . . . . . . . . . . . . . 256 Adding constructors and Java methods to a class . . . . . . . . . . . . . . . . . . 259 Implementing the classes and methods . . . . . . . . . . . . . . . . . . . . . . . . . . 263 Creating relationships between Java types. . . . . . . . . . . . . . . . . . . . . . . . 264 Understanding the sample code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Running the ITSO Bank application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Additional features used for Java applications . . . . . . . . . . . . . . . . . . . . . . . . 282 Analyzing source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

Contents

vii

Creating a run configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Debugging a Java application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 Using the Java scrapbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 Plugable Java Runtime Environment (JRE) . . . . . . . . . . . . . . . . . . . . . . . 289 Exporting Java applications to a JAR file . . . . . . . . . . . . . . . . . . . . . . . . . 290 Running Java applications external to Application Developer . . . . . . . . . 292 Importing Java resources from a JAR file into a project . . . . . . . . . . . . . . 293 Javadoc tooling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 Generating Javadoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Java editor and rapid application development . . . . . . . . . . . . . . . . . . . . . . 300 Navigating through the code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 Using the Outline view to navigate the code . . . . . . . . . . . . . . . . . . . . . . . 301 Using the Package Explorer to navigate the code . . . . . . . . . . . . . . . . . . 302 Using bookmarks to navigate the code . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 Source folding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 Type hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 Smart insert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Marking occurrences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Smart compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Java and file search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Working sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 Quick fix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Quick assist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 Content assist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 Import generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 Adding constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Delegate method generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 Chapter 8. Accelerate development using patterns. . . . . . . . . . . . . . . . . 325 Introduction to pattern implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 Pattern specification and pattern implementation . . . . . . . . . . . . . . . . . . . 326 Pattern implementation and Application Developer . . . . . . . . . . . . . . . . . 326 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 Creating a pattern implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Create a new JET Transform project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Populating the transformation model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 Adding and deriving attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 Generate and edit templates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 Applying the pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 Facade pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 Importing the facade example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351

viii

Rational Application Developer V7 Programming Guide

Facade transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 Running the transformation examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Chapter 9. Develop database applications . . . . . . . . . . . . . . . . . . . . . . . . 355 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 JDBC overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 Setting up the sample database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 Connecting to databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 Creating a database connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 Browsing a database with the Database Explorer . . . . . . . . . . . . . . . . . . 361 Creating SQL statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 Creating a data development project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 Populating the transactions table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364 Creating a select statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 Running the SQL query. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 Developing a Java stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372 Creating a Java stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372 Deploying a Java stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 Running the stored procedure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376 Creating a JavaBean to call a stored procedure . . . . . . . . . . . . . . . . . . . . 377 Using the DB bean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 Developing SQLJ applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 Creating SQLJ files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 Examining the generated SQLJ file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 Testing the SQLJ program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385 Data modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386 Creating a data design project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387 Creating a physical data model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388 Modeling with diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 Generating DDL from physical data model and deploy. . . . . . . . . . . . . . . 393 Modifying the data model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Analyzing the data model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396 Comparing data objects and managing changes . . . . . . . . . . . . . . . . . . . 398 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 Chapter 10. Develop GUI applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 Introduction to the visual editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 Prepare for the sample. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 Creating the project for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 Adding the JDBC driver for Derby to the project . . . . . . . . . . . . . . . . . . . . 405 Setting up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 Importing the model classes for the sample . . . . . . . . . . . . . . . . . . . . . . . 406

Contents

ix

Launching the visual editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 Creating a visual class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 Open an existing class with the visual editor . . . . . . . . . . . . . . . . . . . . . . 409 Visual editor overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 Visual editor layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 Customizing the appearance of the visual editor . . . . . . . . . . . . . . . . . . . 411 Working with the visual editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Resizing a JavaBean component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Code synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Changing the properties of a component . . . . . . . . . . . . . . . . . . . . . . . . . 414 Adding JavaBeans to a visual class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 Working with the Properties view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 Testing the appearance of the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 Adding event handling to GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 Verifying the Java GUI application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 Run the sample GUI as a Java application . . . . . . . . . . . . . . . . . . . . . . . . 422 Automatically add event handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422 visual editor binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 Chapter 11. Develop XML applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 XML overview and technologies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 XML and XML processor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 DTD and XML schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 XSL and XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 XML namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432 XPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432 Rational Application Developer XML tools . . . . . . . . . . . . . . . . . . . . . . . . . . 432 Creating an XML schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 Validating an XML schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440 Generating HTML documentation from an XML schema file . . . . . . . . . . 442 Generating an XML file from an XML schema . . . . . . . . . . . . . . . . . . . . . 442 Editing an XML file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 Working with XSL files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 Transforming an XML file into an HTML file . . . . . . . . . . . . . . . . . . . . . . . 448 XML mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448 Generating JavaBeans from an XML schema . . . . . . . . . . . . . . . . . . . . . 457 Service Data Objects and XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460

x

Rational Application Developer V7 Programming Guide

More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464 Chapter 12. Develop Web applications using JSPs and servlets . . . . . . 465 Introduction to J2EE Web applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 J2EE applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 Model-view-controller (MVC) pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 Web development tooling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472 Web perspective and views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473 Web Site Navigation Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 Web Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476 Page Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476 Page templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477 CSS Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478 Security Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478 File creation wizards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479 Summary of new features in V7.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 RedBank application design. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482 View layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 Controller layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 Implementing the RedBank application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486 Creating the Web project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 Web project directory structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 Importing the RedBank model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 Defining the Web site navigation and appearance . . . . . . . . . . . . . . . . . . 493 Launching the Web Site Designer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502 Developing the static Web resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508 Developing the dynamic Web resources. . . . . . . . . . . . . . . . . . . . . . . . . . 513 Working with JSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521 Testing the Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533 Prerequisites to run the sample Web application . . . . . . . . . . . . . . . . . . . 533 Running the sample Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534 Verifying the RedBank Web application . . . . . . . . . . . . . . . . . . . . . . . . . . 534 RedBank Web application conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 Chapter 13. Develop Web applications using Struts . . . . . . . . . . . . . . . . 541 Introduction to Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542 Model-view-controller (MVC) pattern with Struts. . . . . . . . . . . . . . . . . . . . 542 Application Developer support for Struts. . . . . . . . . . . . . . . . . . . . . . . . . . 545 Preparing for the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547 Setting up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547 Configuring the data source in the WebSphere Server 6.1. . . . . . . . . . . . 547

Contents

xi

Activating Struts development capabilities . . . . . . . . . . . . . . . . . . . . . . . . 547 ITSO Bank Struts Web application overview . . . . . . . . . . . . . . . . . . . . . . 548 Creating a dynamic Web project with Struts support . . . . . . . . . . . . . . . . 550 Developing a Web application using Struts . . . . . . . . . . . . . . . . . . . . . . . . . 553 Creating the Struts components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553 Realizing the Struts components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559 Modify application resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560 Using the Struts validation framework. . . . . . . . . . . . . . . . . . . . . . . . . . . . 561 Page Designer and the Struts tag library . . . . . . . . . . . . . . . . . . . . . . . . . 563 Completing the logon action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 Using the Struts Configuration Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569 Completing the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573 Running the Struts Bank Web application . . . . . . . . . . . . . . . . . . . . . . . . . . 577 Developing a Struts Web application using Tiles . . . . . . . . . . . . . . . . . . . . . 580 Building the Tiles application extension . . . . . . . . . . . . . . . . . . . . . . . . . . 581 Running the Tiles application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584 Importing the final sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586 Chapter 14. Develop Web applications using JSF and SDO . . . . . . . . . . 587 Introduction to JSF, SDO, and AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588 JavaServer Faces (JSF) overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588 Service Data Objects (SDO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 Asynchronous JavaScript and XML (AJAX) . . . . . . . . . . . . . . . . . . . . . . . 594 Preparing for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596 Creating a dynamic Web project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596 Setting up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598 Configuring the data source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 Developing a Web application using JSF and SDO . . . . . . . . . . . . . . . . . . . 599 Creating a dynamic page template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 Views for editing page template files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602 Customizing the page template. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607 Create Faces JSP pages using the Web Diagram Editor . . . . . . . . . . . . . 611 Editing the Faces JSP pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620 Editing the login page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620 Editing the customer details page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633 Editing the account details page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 Running the sample Web application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647 Prerequisites to run sample Web application . . . . . . . . . . . . . . . . . . . . . . 647 Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648 Running the sample Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649 Verifying the sample Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649

xii

Rational Application Developer V7 Programming Guide

Adding AJAX behavior to the sample Web application . . . . . . . . . . . . . . . . 652 Adding type-ahead control to the login page. . . . . . . . . . . . . . . . . . . . . . . 652 Adding AJAX refresh submit behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . 656 Testing the AJAX enabled JSF pages . . . . . . . . . . . . . . . . . . . . . . . . . . . 661 Possible improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662 Developing a JSF page with a Web service call . . . . . . . . . . . . . . . . . . . . . 662 More information on JSF, SDO, and AJAX . . . . . . . . . . . . . . . . . . . . . . . . . 663 Chapter 15. Develop applications using EGL . . . . . . . . . . . . . . . . . . . . . . 665 Introduction to EGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666 EGL key terms and ideas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666 Overview and dependencies of examples in this chapter . . . . . . . . . . . . . 669 EGL installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670 EGL example 1: Simple batch program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671 Rational Application Developer workspace . . . . . . . . . . . . . . . . . . . . . . . . 671 Creating an EGL (non-Web) project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671 Creating a database connection resource . . . . . . . . . . . . . . . . . . . . . . . . 672 Testing a database connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 Adding SQL database support to the EGL (non-Web) project . . . . . . . . . 674 Generating EGL data items, records, SQL access libraries . . . . . . . . . . . 677 Creating the EGL simple batch program . . . . . . . . . . . . . . . . . . . . . . . . . . 679 Compiling and running the EGL simple batch program . . . . . . . . . . . . . . 683 Debugging the EGL simple batch program . . . . . . . . . . . . . . . . . . . . . . . . 685 EGL example 2: Web site with two pages using EGL . . . . . . . . . . . . . . . . . 687 Dependencies for EGL example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688 Starting the application server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688 Creating an EGL Web project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689 Enabling import of EGL source code from other EGL projects . . . . . . . . . 690 Defining a JNDI resource for an EGL Web project . . . . . . . . . . . . . . . . . . 691 Creating the Web list page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696 Creating and modifying the EGL JSF page handler . . . . . . . . . . . . . . . . . 699 Compiling the EGL JSF page handler. . . . . . . . . . . . . . . . . . . . . . . . . . . . 701 Extending the Web list page with customer result data . . . . . . . . . . . . . . 701 Deploying the EGL Web project to the application server. . . . . . . . . . . . . 704 Testing an EGL Web page (EGL Faces JSP Web page) . . . . . . . . . . . . . 705 Changing the default Web browser. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706 Extending the Web list page with a hyperlink to the detail page . . . . . . . . 706 Creating the Web detail page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709 Creating and modifying the EGL JSF page handler . . . . . . . . . . . . . . . . . 709 Compiling the EGL JSF page handler. . . . . . . . . . . . . . . . . . . . . . . . . . . . 711 Completing the Web detail page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711 Final test of the Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715

Contents

xiii

Implementing a detail page with update . . . . . . . . . . . . . . . . . . . . . . . . . . 715 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717 Chapter 16. Develop Web applications using EJBs. . . . . . . . . . . . . . . . . 719 Introduction to Enterprise JavaBeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720 Enterprise JavaBeans overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720 EJB server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722 EJB container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723 EJB components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724 EJB features in Application Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . 730 Sample application overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730 Preparing for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733 Required software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733 Enabling the EJB development capability . . . . . . . . . . . . . . . . . . . . . . . . . 733 Creating and configuring the EJB projects . . . . . . . . . . . . . . . . . . . . . . . . 733 Creating an EJB project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734 Importing a Web project and a Java project . . . . . . . . . . . . . . . . . . . . . . . 736 Setting up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737 Configuring the data source for the ITSOBANK . . . . . . . . . . . . . . . . . . . . 740 Developing an EJB application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742 Creating the entity beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743 Creating the entity relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750 Customizing the entity beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755 Adding the business logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758 Creating custom finders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762 Object-relational mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764 Generating the EJB to RDB mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766 Implementing the session facade. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771 Creating the EJBBank session bean. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771 Completing the session bean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773 Generating the deployed code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781 Testing EJBs with the Universal Test Client. . . . . . . . . . . . . . . . . . . . . . . . . 781 Adapting the Web application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 787 Implementing the ITSOBank class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788 Running the Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791 Complete EJB application interchange file. . . . . . . . . . . . . . . . . . . . . . . . . . 792 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 792 Chapter 17. Develop J2EE application clients . . . . . . . . . . . . . . . . . . . . . 793 Introduction to J2EE application clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794 Overview of the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796 Preparing for the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797 Importing the base EJB enterprise application sample . . . . . . . . . . . . . . . 797

xiv

Rational Application Developer V7 Programming Guide

Setting up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798 Configuring the data source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798 Testing the imported code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799 Developing the J2EE application client . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799 Creating the J2EE application client projects . . . . . . . . . . . . . . . . . . . . . . 800 Configuring the J2EE application client projects . . . . . . . . . . . . . . . . . . . . 801 Importing the graphical user interface and control classes . . . . . . . . . . . . 802 Creating the BankDesktopController class . . . . . . . . . . . . . . . . . . . . . . . . 803 Completing the BankDesktopController class . . . . . . . . . . . . . . . . . . . . . . 804 Registering the BankDesktopController class as the main class . . . . . . . 808 Testing the J2EE application client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808 Packaging the J2EE application client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 810 Running the deployed application client . . . . . . . . . . . . . . . . . . . . . . . . . . 810 Chapter 18. Develop Web services applications . . . . . . . . . . . . . . . . . . . 811 Introduction to Web services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812 Service-oriented architecture (SOA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812 Web services as an SOA implementation. . . . . . . . . . . . . . . . . . . . . . . . . 813 Related Web services standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815 Web services development approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . 816 Web services tools in Application Developer . . . . . . . . . . . . . . . . . . . . . . . . 817 Creating a Web service from existing resources. . . . . . . . . . . . . . . . . . . . 817 Creating a skeleton Web service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 817 Client development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818 Testing tools for Web services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818 Preparing for the samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819 Creating Web services from a JavaBean . . . . . . . . . . . . . . . . . . . . . . . . . . . 820 Creating Web services using the Web Service wizard . . . . . . . . . . . . . . . 821 Resources generated by the Web Service wizard . . . . . . . . . . . . . . . . . . 828 Creating a Web service JSP client and monitoring Web services . . . . . . . . 830 Creating a Web service JSF client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835 Handling exceptions in Web services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837 Adding exception handling code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 838 Watching the SOAP fault using the TCP/IP Monitor . . . . . . . . . . . . . . . . . 839 Creating Web services from an EJB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840 Creating a top-down Web service from a WSDL . . . . . . . . . . . . . . . . . . . . . 842 Designing the WSDL using the WSDL editor . . . . . . . . . . . . . . . . . . . . . . 842 Generating the skeleton JavaBean Web service . . . . . . . . . . . . . . . . . . . 848 Creating Web services with Ant tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849 Running the Web service Ant task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850 Generating SDO facades for Web services . . . . . . . . . . . . . . . . . . . . . . . . . 851 Generating an SDO facade. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853 Implementing the SDO Web service server and client . . . . . . . . . . . . . . . 854

Contents

xv

Running the SDO Web service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855 Web services security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856 Using the WS Security wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858 Running the Web service with security . . . . . . . . . . . . . . . . . . . . . . . . . . . 862 Developing Web services with the Web Services Feature Pack . . . . . . . . . 864 Supported standards and programming model. . . . . . . . . . . . . . . . . . . . . 865 Installing the Web Services Feature Pack . . . . . . . . . . . . . . . . . . . . . . . . 866 Enabling the WebSphere Application Server v6.1 test environment with the Feature Pack for Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . 866 Creating a Web service and a client using the JAX-WS runtime . . . . . . . 867 Securing the Web service and client with the RAMP policy set . . . . . . . . 873 Sending binary data using MTOM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879 Creating Web services using annotations . . . . . . . . . . . . . . . . . . . . . . . . . 889 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896 Chapter 19. Develop portal applications. . . . . . . . . . . . . . . . . . . . . . . . . . 897 Introduction to portal technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 898 Portal concepts and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 898 IBM WebSphere Portal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901 Portal and portlet development features in Application Developer . . . . . . 902 Setting up Application Developer with the Portal test environment. . . . . . 903 Developing applications for WebSphere Portal . . . . . . . . . . . . . . . . . . . . . . 903 Portal samples and tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903 Development strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904 Portal tools for developing portals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907 Developing portal solutions using portal tools . . . . . . . . . . . . . . . . . . . . . . . 914 Creating CRUD Faces portlets using SDO . . . . . . . . . . . . . . . . . . . . . . . . 915 Consuming a Web service in a portlet and displaying the results using a Faces component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929 Exploring Application Developer tooling for Portal projects . . . . . . . . . . . 942 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960 Part 3. Test and debug applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961 Chapter 20. Servers and server configuration . . . . . . . . . . . . . . . . . . . . . 963 Introduction to server configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964 Compatible application servers for Application Developer . . . . . . . . . . . . 964 Local and remote test environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965 Understanding WebSphere Application Server V6.1 profiles . . . . . . . . . . . . 966 Types of profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 967 WebSphere Application Server V6.1 installation . . . . . . . . . . . . . . . . . . . . . 969 Using WebSphere Application Server V6.1 profiles . . . . . . . . . . . . . . . . . . . 969 Creating a new profile using the WebSphere Profile wizard . . . . . . . . . . . 969 Verifying the new WebSphere profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . 971

xvi

Rational Application Developer V7 Programming Guide

Deleting a WebSphere profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972 Defining a new server in Application Developer . . . . . . . . . . . . . . . . . . . . 973 Customizing a server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976 Share a WebSphere profile among developers . . . . . . . . . . . . . . . . . . . . 979 Defining a server for each workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . 980 Adding and removing applications to and from a server . . . . . . . . . . . . . . . 980 Adding an application to the server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 981 Removing an application from a server. . . . . . . . . . . . . . . . . . . . . . . . . . . 981 Configuring application and server resources . . . . . . . . . . . . . . . . . . . . . . . 983 Creating a data source in the enhanced EAR . . . . . . . . . . . . . . . . . . . . . . 985 Configuring server resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 989 Configuring security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 990 Configuring security in the server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 990 Configuring security in the Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . 992 Developing automation scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993 Creating a Jython project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993 Creating Jython script files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993 Editing Jython script files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 994 Running administrative script files on WebSphere Application Server . . . 994 Generating WebSphere admin commands for Jython scripts . . . . . . . . . . 996 Debugging Jython scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 999 Jython script for application deployment . . . . . . . . . . . . . . . . . . . . . . . . . . 999 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 999 Chapter 21. Test using JUnit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001 Introduction to application testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1002 Test concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1002 Test phases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1002 Test environments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1004 Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005 Test case execution and recording results . . . . . . . . . . . . . . . . . . . . . . . 1005 Benefits of unit and component testing . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005 Benefits of testing frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006 Test & Performance Tools Platform (TPTP). . . . . . . . . . . . . . . . . . . . . . . . 1007 JUnit testing [without using TPTP] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007 JUnit fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 What is new in JUnit 4.x? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 Prepare the JUnit sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013 Creating a JUnit test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1014 Creating a JUnit test suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1019 Running the JUnit test case or JUnit test suite . . . . . . . . . . . . . . . . . . . . 1020 JUnit testing using TPTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022 Creating the TPTP JUnit sample. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022

Contents

xvii

Running the TPTP JUnit test. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027 Analyzing the test results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028 Web application testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031 Preparing for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031 Recording a test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1032 Editing the test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1034 Generating an executable test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035 Running the test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035 Analyzing the test results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1037 Generating test reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1040 Chapter 22. Debug local and remote applications . . . . . . . . . . . . . . . . . 1041 Overview of Application Developer debugging tools . . . . . . . . . . . . . . . . . . 1042 Supported languages and environments . . . . . . . . . . . . . . . . . . . . . . . . 1042 Basic Java debugging features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1042 XSLT debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046 Remote debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048 Summary of new features in V7.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049 Debugging a Web application on a local server . . . . . . . . . . . . . . . . . . . . . 1050 Importing the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1051 Running the sample application in debug mode . . . . . . . . . . . . . . . . . . . 1051 Setting breakpoints in a Java class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1052 Watching variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055 Evaluating and watching expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056 Using the Display view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057 Working with breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1058 Set breakpoints in a JSP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1059 Debugging a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1060 Debugging a Web application on a remote server . . . . . . . . . . . . . . . . . . . 1062 Exporting the RedBank as an EAR file . . . . . . . . . . . . . . . . . . . . . . . . . . 1062 Deploying the RedBank application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063 Configuring debug on a remote WebSphere Application Server . . . . . . 1064 Attaching to the remote server in Application Developer . . . . . . . . . . . . 1064 Debugging a remote application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066 Uninstalling the remote application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068 Jython debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068 Debugging a sample Jython script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068

xviii

Rational Application Developer V7 Programming Guide

More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1071 Part 4. Deploy and profile applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1073 Chapter 23. Build applications with Ant . . . . . . . . . . . . . . . . . . . . . . . . . 1075 Introduction to Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076 Ant build files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076 Ant tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077 Ant features in Application Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077 Preparing for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078 Creating a build file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079 Project definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1080 Global properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1080 Build targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1081 Content assist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1082 Code snippets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083 Formatting an Ant script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086 Defining the format of an Ant script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087 Problems view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089 Building a simple Java application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1090 Running Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1090 Ant console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1093 Rerun Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1093 Forced build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1093 Classpath problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1094 Running the sample application to verify the Ant build . . . . . . . . . . . . . . 1094 Building a J2EE application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1094 J2EE application deployment packaging . . . . . . . . . . . . . . . . . . . . . . . . 1095 Preparing for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095 Creating the build script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096 Running the Ant J2EE application build . . . . . . . . . . . . . . . . . . . . . . . . . 1097 Running Ant outside of Application Developer . . . . . . . . . . . . . . . . . . . . . . 1099 Preparing for the headless build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1099 Running the headless Ant build script . . . . . . . . . . . . . . . . . . . . . . . . . . . 1100 More information on Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1101 Chapter 24. Deploy enterprise applications . . . . . . . . . . . . . . . . . . . . . . 1103 Introduction to application deployment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1104 Common deployment considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 1104 J2EE application components and deployment modules . . . . . . . . . . . . 1105 Deployment descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105 WebSphere deployment architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . 1108 Java and WebSphere class loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1116

Contents

xix

Preparing for the deployment of the EJB application . . . . . . . . . . . . . . . . . 1120 Reviewing the deployment scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . 1120 Installing the prerequisite software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1121 Importing the sample application project interchange files . . . . . . . . . . . 1122 Sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1122 Packaging the application for deployment . . . . . . . . . . . . . . . . . . . . . . . . . 1123 Generating the EJB to RDB mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . 1123 Customizing the deployment descriptors . . . . . . . . . . . . . . . . . . . . . . . . 1125 Removing the enhanced EAR data source . . . . . . . . . . . . . . . . . . . . . . . 1126 Generating the deploy code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1126 Exporting the EAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1127 Manual deployment of enterprise applications . . . . . . . . . . . . . . . . . . . . . . 1128 Configuring the data source in the application server . . . . . . . . . . . . . . . 1128 Installing the enterprise applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1135 Starting the enterprise applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1138 Verifying the application after manual installation . . . . . . . . . . . . . . . . . . 1139 Uninstalling the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1141 Automated deployment using Jython based wsadmin scripting. . . . . . . . . 1141 Overview of wsadmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1142 Overview of Jython . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1142 Developing a Jython script to deploy the ITSO Bank . . . . . . . . . . . . . . . 1144 Executing the Jython script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1152 Verifying the application after automatic installation . . . . . . . . . . . . . . . . 1154 Generation Jython source code for wsadmin commands . . . . . . . . . . . . 1154 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1154 Chapter 25. Profile applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155 Introduction to profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1156 Profiling features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1156 Profiling architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1159 Profiling and Logging perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1161 Preparing for the profiling sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1162 Prerequisite software installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1162 Enabling the Profiling and Logging capability . . . . . . . . . . . . . . . . . . . . . 1163 Importing the sample project interchange file . . . . . . . . . . . . . . . . . . . . . 1164 Publishing and running sample application . . . . . . . . . . . . . . . . . . . . . . . 1165 Profiling the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1165 Starting server in profile mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1165 Profile on server dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1166 Collecting profiling data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1170 Analyzing profiling data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1171 Refreshing the views and resetting data . . . . . . . . . . . . . . . . . . . . . . . . . 1182 Ending the profiling session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1182

xx

Rational Application Developer V7 Programming Guide

More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1182 Part 5. Team development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183 Chapter 26. ClearCase integration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1185 Introduction to IBM Rational ClearCase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1186 ClearCase overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1186 ClearCase terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1187 ClearCase LT setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1188 ClearCase integration feature of Application Developer . . . . . . . . . . . . . . 1188 ClearCase Help in Application Developer . . . . . . . . . . . . . . . . . . . . . . . . 1188 ClearCase preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1189 Enable ClearCase capability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1190 Integration scenario overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1190 ClearCase setup for a new project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1192 Setting up the ClearCase server environment . . . . . . . . . . . . . . . . . . . . 1192 Joining a UCM project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1196 Developer 1 creates a development stream and view . . . . . . . . . . . . . . 1197 Developer 1 creates a Web project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1198 Developer 1 adds the project to ClearCase source control. . . . . . . . . . . 1200 Development scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1201 Developer 1 adds a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1201 Developer 1 checks in all dependent files . . . . . . . . . . . . . . . . . . . . . . . . 1203 Developer 1 delivers work to the integration stream . . . . . . . . . . . . . . . . 1204 Developer 1 makes a baseline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1205 Developer 2 joins the project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1206 Developer 2 creates a development stream and view . . . . . . . . . . . . . . 1206 Developer 2 imports the project into the workspace . . . . . . . . . . . . . . . . 1207 Developer 2 modifies the servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1208 Developer 2 delivers work to the integration stream . . . . . . . . . . . . . . . . 1209 Developer 1 modifies the servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1209 Developer 1 delivers new work to the integration stream . . . . . . . . . . . . 1210 Version tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1212 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1212 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1212 Chapter 27. CVS integration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1213 Introduction to CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1214 CVS features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1214 CVS support within Application Developer. . . . . . . . . . . . . . . . . . . . . . . . . 1216 New features available with Application Developer V7.0 . . . . . . . . . . . . 1217 CVSNT Server installation and implementation . . . . . . . . . . . . . . . . . . . . . 1218 Installing the CVS Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1218 Configuring the CVS Server repository . . . . . . . . . . . . . . . . . . . . . . . . . . 1219

Contents

xxi

Creating the Windows users and groups used by CVS . . . . . . . . . . . . . 1222 Verifying the CVSNT installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1223 Creating CVS users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1224 CVS client configuration for Application Developer . . . . . . . . . . . . . . . . . . 1225 Configuring the CVS team capability . . . . . . . . . . . . . . . . . . . . . . . . . . . 1225 Accessing the CVS repository. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1226 Configuring CVS in Application Developer. . . . . . . . . . . . . . . . . . . . . . . . . 1227 Label decorations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1228 File content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1229 Ignored resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1230 CVS-specific settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1232 CVS keyword substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1233 Development scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1236 Create and share the project (step 1 - cvsuser1) . . . . . . . . . . . . . . . . . . 1237 Adding a shared project to the workspace (step 2 - cvsuser2) . . . . . . . . 1240 Modifying the servlet (step 2 - cvsuser1) . . . . . . . . . . . . . . . . . . . . . . . . 1244 Synchronizing with the repository (step 3 - cvsuser1). . . . . . . . . . . . . . . 1245 Synchronizing with the repository (step 3 - cvsuser2). . . . . . . . . . . . . . . 1247 Parallel development (step 4 - cvsuser1 and cvsuser2) . . . . . . . . . . . . . 1247 Creating a version (step 5 - cvsuser1) . . . . . . . . . . . . . . . . . . . . . . . . . . 1253 CVS resource history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1254 Comparisons in CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1256 Comparing a workspace file with the repository . . . . . . . . . . . . . . . . . . . 1256 Comparing two revisions in repository . . . . . . . . . . . . . . . . . . . . . . . . . . 1258 Annotations in CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1259 Branches in CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1261 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1262 Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1266 Working with patches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1270 Disconnecting a project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1271 Team Synchronizing perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1272 Custom configuration of resource synchronization . . . . . . . . . . . . . . . . . 1272 Schedule synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1276 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1277 Part 6. Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1279 Appendix A. Product installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1281 IBM Installation Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1282 Installing IBM Rational Application Developer . . . . . . . . . . . . . . . . . . . . . . . 1283 Installing the license for Rational Application Developer . . . . . . . . . . . . 1291 Updating Rational Application Developer . . . . . . . . . . . . . . . . . . . . . . . . 1293 Uninstalling Rational Application Developer . . . . . . . . . . . . . . . . . . . . . . 1294

xxii

Rational Application Developer V7 Programming Guide

Installing Enterprise Generation Language . . . . . . . . . . . . . . . . . . . . . . . . . 1295 Installing the WebSphere Portal V6.0 test environment . . . . . . . . . . . . . . . 1296 Installing WebSphere Portal V6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1296 Adding WebSphere Portal V6.0 to Application Developer . . . . . . . . . . . 1299 Upgrading the Portal Server runtime to Version 6.0.1 . . . . . . . . . . . . . . 1302 Optimizing the Portal Server for development . . . . . . . . . . . . . . . . . . . . 1302 Installing IBM Rational ClearCase LT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1304 Appendix B. Additional material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1307 Locating the Web material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1308 System requirements for downloading the Web material . . . . . . . . . . . . 1308 Using the sample code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1308 Unpacking the sample code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1308 Description of the sample code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1309 Interchange files with solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1310 Importing sample code from a project interchange file. . . . . . . . . . . . . . . . . 1310 Setting up the ITSOBANK database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1312 Derby. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1312 DB2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1312 Configuring the data source in WebSphere Application Server . . . . . . . . . . 1313 Starting the WebSphere Application Server . . . . . . . . . . . . . . . . . . . . . . 1313 Configuring the environment variables . . . . . . . . . . . . . . . . . . . . . . . . . . 1314 Configuring J2C authentication data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1314 Configuring the JDBC provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1315 Creating the data source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1316 Abbreviations and acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1317 Related publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1321 IBM Redbooks publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1321 Other publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1321 Online resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1322 How to get Redbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1323 Help from IBM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1323 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1325

Contents

xxiii

xxiv

Rational Application Developer V7 Programming Guide

NoticesThis information was developed for products and services offered in the U.S.A. IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to evaluate and verify the operation of any non-IBM product, program, or service. IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to: IBM Director of Licensing, IBM Corporation, North Castle Drive, Armonk, NY 10504-1785 U.S.A. The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk. IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you. Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental. COPYRIGHT LICENSE: This informati