RAD Dev Guide

1460
ibm.com/redbooks Rational Application Developer V6 Programming Guide John Ganci Fabio Ferraz Hari Kanangi Kiriya Keat George Kroner Juha Nevalainen Nicolai Nielsen Richard Raszka Neil Weightman 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 Dev Guide

Front cover

Rational Application Developer V6 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

John Ganci Fabio Ferraz Hari Kanangi Kiriya Keat George Kroner Juha Nevalainen Nicolai Nielsen Richard Raszka Neil Weightman

ibm.com/redbooks

International Technical Support Organization Rational Application Developer V6 Programming Guide June 2005

SG24-6449-00

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

First Edition (June 2005) This edition applies to IBM Rational Application Developer V6.0 and IBM WebSphere Application Server V6.0. Copyright International Business Machines Corporation 2005. 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii The team that wrote this redbook. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Become a published author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi Comments welcome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvii Summary of changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvii June 2005, First Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvii Part 1. Introduction to Rational Application Developer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 Introduction and concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.1.1 IBM Rational Software Development Platform . . . . . . . . . . . . . . . . . . 4 1.1.2 Version 6 terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.1.3 Application development challenges . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.1.4 Key themes of Version 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.2 Product packaging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.2.1 Rational Developer supported platforms and databases . . . . . . . . . . 9 1.2.2 Rational Application Developer V6 product packaging . . . . . . . . . . . 10 1.2.3 Rational Web Developer V6 product packaging . . . . . . . . . . . . . . . . 11 1.3 Product features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.3.1 Summary of new features in Version 6 . . . . . . . . . . . . . . . . . . . . . . . 14 1.3.2 Specification versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.3.3 Eclipse and IBM Rational Software Development Platform . . . . . . . 19 1.3.4 Test server environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.3.5 Licensing and installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.3.6 Migration and coexistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.3.7 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1.4 Sample code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Chapter 2. Programming technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.1 Desktop applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.1.1 Simple desktop applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.1.2 Database access. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.1.3 Graphical user interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 2.1.4 Extensible Markup Language (XML) . . . . . . . . . . . . . . . . . . . . . . . . . 38 2.2 Static Web sites. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

Copyright IBM Corp. 2005. All rights reserved.

iii

2.2.1 Hypertext Transfer Protocol (HTTP) . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.2.2 HyperText Markup Language (HTML) . . . . . . . . . . . . . . . . . . . . . . . 42 2.3 Dynamic Web applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.3.1 Simple Web applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.3.2 Struts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.3.3 JavaServer Faces (JSF) and Service Data Objects (SDO) . . . . . . . 52 2.3.4 Portal applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 2.4 Enterprise JavaBeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 2.4.1 Different types of EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 2.4.2 Other EJB features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 2.4.3 Requirements for the development environment . . . . . . . . . . . . . . . 61 2.5 J2EE Application Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 2.5.1 Application Programming Interfaces (APIs) . . . . . . . . . . . . . . . . . . . 63 2.5.2 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 2.5.3 Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 2.5.4 Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 2.5.5 Requirements for the development environment . . . . . . . . . . . . . . . 65 2.6 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 2.6.1 Web Services in J2EE V1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 2.7 Messaging systems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 2.7.1 Java Message Service (JMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 2.7.2 Message-driven EJBs (MDBs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 2.7.3 Requirements for the development environment . . . . . . . . . . . . . . . 72 Chapter 3. Workbench setup and preferences . . . . . . . . . . . . . . . . . . . . . . 75 3.1 Workbench basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 3.1.1 Workspace basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 3.1.2 Rational Application Developer log files . . . . . . . . . . . . . . . . . . . . . . 83 3.2 Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 3.2.1 Automatic builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 3.2.2 Clean build (manual) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.2.3 Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.2.4 File associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 3.2.5 Local history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 3.2.6 Perspectives preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 3.2.7 Internet preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 3.3 Java development preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 3.3.1 Java classpath variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 3.3.2 Appearance of Java elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 3.3.3 Code style and formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 3.3.4 Compiler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 3.3.5 Java editor settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 3.3.6 Installed JREs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

iv

Rational Application Developer V6 Programming Guide

3.3.7 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 3.3.8 Code review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Chapter 4. Perspectives, views, and editors. . . . . . . . . . . . . . . . . . . . . . . 131 4.1 Integrated development environment (IDE) . . . . . . . . . . . . . . . . . . . . . . 132 4.1.1 Rational Application Developer online help. . . . . . . . . . . . . . . . . . . 132 4.1.2 Perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 4.1.3 Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 4.1.4 Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 4.1.5 Perspective layout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 4.1.6 Switching perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 4.1.7 Specifying the default perspective . . . . . . . . . . . . . . . . . . . . . . . . . 140 4.1.8 Organizing and customizing perspectives. . . . . . . . . . . . . . . . . . . . 140 4.2 Available perspectives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 4.2.1 CVS Repository Exploring perspective . . . . . . . . . . . . . . . . . . . . . . 143 4.2.2 Data perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 4.2.3 Debug perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 4.2.4 Generic Log Adapter perspective . . . . . . . . . . . . . . . . . . . . . . . . . . 148 4.2.5 J2EE perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 4.2.6 Java perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 4.2.7 Java Browsing perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 4.2.8 Java Type Hierarchy perspective . . . . . . . . . . . . . . . . . . . . . . . . . . 155 4.2.9 Plug-in Development perspective . . . . . . . . . . . . . . . . . . . . . . . . . . 157 4.2.10 Profiling and Logging perspective . . . . . . . . . . . . . . . . . . . . . . . . . 158 4.2.11 Resource perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 4.2.12 Team Synchronizing perspective . . . . . . . . . . . . . . . . . . . . . . . . . 160 4.2.13 Test perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 4.2.14 Web perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 4.2.15 Progress view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 4.3 Rational Product Updater . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Chapter 5. Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 5.1 J2EE architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 5.1.1 EAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 5.1.2 WAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 5.1.3 EJB JAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 5.1.4 J2EE Application Client JAR files . . . . . . . . . . . . . . . . . . . . . . . . . . 171 5.1.5 RAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 5.2 Projects and folders. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 5.3 Rational Application Developer projects . . . . . . . . . . . . . . . . . . . . . . . . . 173 5.3.1 Enterprise Application project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 5.3.2 J2EE Application Client project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 5.3.3 Dynamic Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

Contents

v

5.3.4 Static Web Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 5.3.5 EJB project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 5.3.6 Connector project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 5.3.7 Java project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 5.3.8 Simple project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 5.3.9 Server project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 5.3.10 Component test project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 5.3.11 Checkout projects from CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 5.4 Creating a new project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 5.5 Project properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 5.6 Rational Application Developer samples. . . . . . . . . . . . . . . . . . . . . . . . . 181 5.6.1 The samples gallery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Part 2. Develop applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Chapter 6. RUP and UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 6.2 Rational Unified Process (RUP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 6.2.1 Process Advisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 6.2.2 Process Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 6.2.3 Setting process preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 6.3 Visualize applications with UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 6.3.1 Unified Modeling Language (UML) . . . . . . . . . . . . . . . . . . . . . . . . . 195 6.3.2 Browse diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 6.3.3 Topic Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 6.3.4 Static Method Sequence Diagram . . . . . . . . . . . . . . . . . . . . . . . . . 203 6.3.5 Class Diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 6.3.6 Sequence Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 6.3.7 J2EE visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 6.4 More information on UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 Chapter 7. Develop Java applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 7.1 Java perspective overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 7.1.1 Package Explorer view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 7.1.2 Call Hierarchy view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 7.1.3 Type Hierarch view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 7.1.4 Problems view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 7.1.5 Declaration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 7.1.6 Code review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 7.1.7 Outline view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 7.1.8 Diagram Navigator view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 7.2 Develop the Java Bank application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 7.2.1 Java Bank application overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 7.2.2 Create a Java Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

vi

Rational Application Developer V6 Programming Guide

7.2.3 Create a class diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 7.2.4 Create Java packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 7.2.5 Create a Java interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 7.2.6 Create Java classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 7.2.7 Create the Java attributes and accessor methods . . . . . . . . . . . . . 254 7.2.8 Add method declarations to an interface. . . . . . . . . . . . . . . . . . . . . 258 7.2.9 Add Java methods and constructors . . . . . . . . . . . . . . . . . . . . . . . . 262 7.2.10 Define relationships (extends, implements, association) . . . . . . . 267 7.2.11 Implement the methods for each class . . . . . . . . . . . . . . . . . . . . . 270 7.2.12 Run the Java Bank application . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 7.3 Additional features used for Java applications . . . . . . . . . . . . . . . . . . . . 286 7.3.1 Locating compile errors in your code . . . . . . . . . . . . . . . . . . . . . . . 287 7.3.2 Running your programs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 7.3.3 Debug your programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 7.3.4 Java Scrapbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 7.3.5 Pluggable Java Runtime Environment (JRE) . . . . . . . . . . . . . . . . . 296 7.3.6 Add a JAR file to the classpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 7.3.7 Export the Java code to a JAR file . . . . . . . . . . . . . . . . . . . . . . . . . 299 7.3.8 Run the Java application external to Application Developer . . . . . . 301 7.3.9 Import a Java JAR file into a project . . . . . . . . . . . . . . . . . . . . . . . . 301 7.3.10 Utility Java Projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 7.3.11 Javadoc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 7.4 Java editor and Rapid Application Development. . . . . . . . . . . . . . . . . . . 311 7.4.1 Navigate through the code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 7.4.2 Source folding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 7.4.3 Type hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 7.4.4 Smart Insert. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 7.4.5 Mark occurrences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 7.4.6 Word skipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 7.4.7 Smart compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 7.4.8 Java search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 7.4.9 Working sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 7.4.10 Quick Assist (Quick Fix) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 7.4.11 Code Assist (content) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 7.4.12 Import generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 7.4.13 Generate getters and setters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 7.4.14 Override/implement methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 7.4.15 Adding constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 7.4.16 Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 Chapter 8. Develop Java database applications . . . . . . . . . . . . . . . . . . . 333 8.1 Introduction to Java database programming . . . . . . . . . . . . . . . . . . . . . . 334 8.1.1 JDBC overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334

Contents

vii

8.1.2 Data source versus direct connection . . . . . . . . . . . . . . . . . . . . . . . 335 8.1.3 XMI and DDL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 8.1.4 Rational Application Developer database features . . . . . . . . . . . . . 336 8.2 Preparing for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 8.2.1 Import the BankDB sample project . . . . . . . . . . . . . . . . . . . . . . . . . 337 8.2.2 Set up the BANK sample database. . . . . . . . . . . . . . . . . . . . . . . . . 338 8.3 Data perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 8.3.1 Data Definition view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 8.3.2 Database Explorer view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 8.3.3 DB Output view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 8.3.4 Navigator view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 8.4 Create databases and tables from scripts. . . . . . . . . . . . . . . . . . . . . . . . 343 8.4.1 Create a database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 8.4.2 Create a database connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 8.4.3 Create the database tables from scripts . . . . . . . . . . . . . . . . . . . . . 349 8.4.4 Populate database tables with data . . . . . . . . . . . . . . . . . . . . . . . . 352 8.5 Create and work with database objects . . . . . . . . . . . . . . . . . . . . . . . . . 354 8.5.1 Create a database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 8.5.2 Create a database connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 8.5.3 Create a schema. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 8.5.4 Create a table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 8.5.5 Generate a DDL file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 8.5.6 Deploy DDL from the workspace to a database . . . . . . . . . . . . . . . 362 8.5.7 Copy database objects from a DDL file to a workspace . . . . . . . . . 362 8.5.8 Generate DDL and XSD files for database objects . . . . . . . . . . . . . 365 8.6 UML visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 8.6.1 Class diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 8.6.2 Information engineering (IE) diagrams . . . . . . . . . . . . . . . . . . . . . . 374 8.6.3 IDEF1X (Integrated Definition Extended) diagrams . . . . . . . . . . . . 375 8.7 Create SQL statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376 8.7.1 Using the SQL Statement wizard . . . . . . . . . . . . . . . . . . . . . . . . . . 376 8.7.2 Using the SQL Query Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 8.8 Access a database from a Java application . . . . . . . . . . . . . . . . . . . . . . 389 8.8.1 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 8.8.2 Access the database using the DriverManager . . . . . . . . . . . . . . . 390 8.8.3 Access using a data source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 8.9 Java stored procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 8.9.1 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 8.9.2 Create a Java stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 8.9.3 Build a stored procedure (deploy to database) . . . . . . . . . . . . . . . . 405 8.9.4 Java DriverManager access to a Java stored procedure . . . . . . . . 408 8.9.5 JavaBean access to Java stored procedure . . . . . . . . . . . . . . . . . . 409

viii

Rational Application Developer V6 Programming Guide

Chapter 9. Develop GUI applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 9.1 Introduction to the Visual Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 9.2 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 9.2.1 Create the project for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . 417 9.2.2 Add JDBC driver for Cloudscape to project . . . . . . . . . . . . . . . . . . 417 9.2.3 Set up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418 9.2.4 Import the model classes for the sample . . . . . . . . . . . . . . . . . . . . 419 9.3 Launching the Visual Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 9.3.1 Create a visual class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 9.3.2 Open an existing class with the Visual Editor . . . . . . . . . . . . . . . . . 422 9.4 Visual Editor overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 9.4.1 Visual Editor layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 9.4.2 Customizing the appearance of the Visual Editor . . . . . . . . . . . . . . 424 9.5 Work with the Visual Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 9.5.1 Resize a JavaBean component . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 9.5.2 Code synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 9.5.3 Changing the properties of a component . . . . . . . . . . . . . . . . . . . . 428 9.5.4 Add JavaBeans to a visual class. . . . . . . . . . . . . . . . . . . . . . . . . . . 428 9.5.5 Work with the Properties view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432 9.5.6 Testing the appearance of the GUI . . . . . . . . . . . . . . . . . . . . . . . . . 433 9.5.7 Add event handling to GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 9.5.8 Verify the Java GUI application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 9.5.9 Run the sample GUI as a Java application . . . . . . . . . . . . . . . . . . . 436 9.5.10 Automatically add event handling . . . . . . . . . . . . . . . . . . . . . . . . . 437 9.5.11 Visual Editor binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438 Chapter 10. Develop XML applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 10.1 XML overview and technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 10.1.1 XML and XML processor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 10.1.2 DTD and XML schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 10.1.3 XSL and XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 10.1.4 XML namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 10.1.5 XPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 10.2 Rational Application Developer XML tools . . . . . . . . . . . . . . . . . . . . . . 447 10.2.1 Create a project for XML sample . . . . . . . . . . . . . . . . . . . . . . . . . 448 10.2.2 Work with DTD files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 10.2.3 Work with XML schema files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458 10.2.4 Work with XML files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 10.2.5 Work with XSL files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482 10.2.6 Transform an XML file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 10.2.7 Java code generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496 10.3 Where to find more information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497

Contents

ix

Chapter 11. Develop Web applications using JSPs and servlets . . . . . . 499 11.1 Introduction to Web applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500 11.1.1 Concepts and technologies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500 11.1.2 Model-view-controller (MVC) pattern . . . . . . . . . . . . . . . . . . . . . . 503 11.2 Web development tooling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 11.2.1 Web perspective and views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506 11.2.2 Web Projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507 11.2.3 Web Site Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508 11.2.4 Page Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 11.2.5 Page templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510 11.2.6 CSS Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511 11.2.7 Javascript Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511 11.2.8 WebArt Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511 11.2.9 AnimatedGif Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511 11.2.10 File creation wizards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512 11.3 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513 11.3.1 ITSO Bank Web application overview . . . . . . . . . . . . . . . . . . . . . . 514 11.3.2 Create a Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517 11.3.3 Web Project directory structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 522 11.3.4 Import the ITSO Bank model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 11.4 Define the site navigation and appearance . . . . . . . . . . . . . . . . . . . . . . 524 11.4.1 Launch the Web Site Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 11.4.2 Create a new page template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 11.4.3 Customize a page template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531 11.4.4 Customize a style sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 11.4.5 Create the Web site navigation and pages . . . . . . . . . . . . . . . . . . 538 11.4.6 Verify the site navigation and page templates . . . . . . . . . . . . . . . 542 11.5 Develop the static Web resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544 11.5.1 Create the index.html page content (text, links) . . . . . . . . . . . . . . 544 11.5.2 Create the rates.html page content (tables) . . . . . . . . . . . . . . . . . 546 11.5.3 Create the insurance.html page content (list) . . . . . . . . . . . . . . . . 547 11.5.4 Create the redbank.html page content (forms) . . . . . . . . . . . . . . . 548 11.6 Develop the dynamic Web resources . . . . . . . . . . . . . . . . . . . . . . . . . . 549 11.6.1 Creating model classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550 11.6.2 Working with servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576 11.6.3 Working with JSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595 11.7 Test the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610 11.7.1 Prerequisites to run sample Web application . . . . . . . . . . . . . . . . 611 11.7.2 Run the sample Web application . . . . . . . . . . . . . . . . . . . . . . . . . 611 11.7.3 Verify the sample Web application . . . . . . . . . . . . . . . . . . . . . . . . 611 Chapter 12. Develop Web applications using Struts . . . . . . . . . . . . . . . . 615 12.1 Introduction to Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616

x

Rational Application Developer V6 Programming Guide

12.1.1 Model-view-controller (MVC) pattern with Struts. . . . . . . . . . . . . . 616 12.1.2 Rational Application Developer support for Struts . . . . . . . . . . . . 619 12.2 Prepare for the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620 12.2.1 ITSO Bank Struts Web application overview . . . . . . . . . . . . . . . . 620 12.2.2 Create a Dynamic Web Project with Struts support . . . . . . . . . . . 622 12.2.3 Add JDBC driver for Cloudscape to project . . . . . . . . . . . . . . . . . 628 12.2.4 Set up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629 12.2.5 Configure the data source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630 12.3 Develop a Web application using Struts . . . . . . . . . . . . . . . . . . . . . . . . 632 12.3.1 Create the Struts components . . . . . . . . . . . . . . . . . . . . . . . . . . . 632 12.3.2 Realize the Struts components . . . . . . . . . . . . . . . . . . . . . . . . . . . 640 12.3.3 Modify ApplicationResources.properties . . . . . . . . . . . . . . . . . . . . 652 12.3.4 Struts validation framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653 12.3.5 Page Designer and the Struts tag library . . . . . . . . . . . . . . . . . . . 655 12.3.6 Using the Struts configuration file editor . . . . . . . . . . . . . . . . . . . . 659 12.4 Import and run the Struts sample application . . . . . . . . . . . . . . . . . . . . 665 12.4.1 Import the Struts Bank Web application sample . . . . . . . . . . . . . . 665 12.4.2 Prepare the application and sample database . . . . . . . . . . . . . . . 666 12.4.3 Run the Struts Bank Web application sample . . . . . . . . . . . . . . . . 666 Chapter 13. Develop Web applications using JSF and SDO . . . . . . . . . . 673 13.1 Introduction to JSF and SDO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 13.1.1 JavaServer Faces (JSF) overview . . . . . . . . . . . . . . . . . . . . . . . . 674 13.1.2 Service Data Objects (SDO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678 13.2 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678 13.2.1 Create a Dynamic Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . . 679 13.2.2 Set up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681 13.2.3 Configure the data source via the enhanced EAR . . . . . . . . . . . . 681 13.3 Develop a Web application using JSF and SDO. . . . . . . . . . . . . . . . . . 684 13.3.1 Create a page template. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684 13.3.2 Useful views for editing page template files . . . . . . . . . . . . . . . . . 687 13.3.3 Customize the page template . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695 13.3.4 Create JSF resources using the Web Diagram tool . . . . . . . . . . . 700 13.3.5 Edit a JSF page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 13.3.6 Completing the SDO example. . . . . . . . . . . . . . . . . . . . . . . . . . . . 730 13.4 Run the sample Web application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746 13.4.1 Prerequisites to run sample Web application . . . . . . . . . . . . . . . . 746 13.4.2 Run the sample Web application . . . . . . . . . . . . . . . . . . . . . . . . . 747 13.4.3 Verify the sample Web application . . . . . . . . . . . . . . . . . . . . . . . . 747 Chapter 14. Develop Web applications using EGL . . . . . . . . . . . . . . . . . 751 14.1 Introduction to EGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752 14.1.1 Programming paradigms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752

Contents

xi

14.1.2 IBM Enterprise Generation Language. . . . . . . . . . . . . . . . . . . . . . 753 14.1.3 IBM EGL and Rational brand software . . . . . . . . . . . . . . . . . . . . . 758 14.1.4 IBM EGL feature enhancements. . . . . . . . . . . . . . . . . . . . . . . . . . 759 14.1.5 Where to find more information on EGL . . . . . . . . . . . . . . . . . . . . 761 14.2 IBM EGL tooling in Rational Developer products . . . . . . . . . . . . . . . . . 761 14.2.1 EGL preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761 14.2.2 EGL perspective and views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762 14.2.3 EGL projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763 14.2.4 EGL wizards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763 14.2.5 EGL migration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764 14.2.6 EGL debug support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765 14.2.7 EGL Web application components . . . . . . . . . . . . . . . . . . . . . . . . 765 14.3 Prepare for the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767 14.3.1 Install the EGL component of Rational Application Developer . . . 768 14.3.2 Enable the EGL development capability . . . . . . . . . . . . . . . . . . . . 771 14.3.3 Install DB2 Universal Database . . . . . . . . . . . . . . . . . . . . . . . . . . 773 14.3.4 Create an EGL Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773 14.3.5 Set up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777 14.3.6 Configure EGL preferences for SQL database connection . . . . . . 779 14.3.7 Configure the data source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 780 14.3.8 Configure the DB2 JDBC class path environment variables . . . . . 783 14.4 Develop the Web application using EGL . . . . . . . . . . . . . . . . . . . . . . . . 784 14.4.1 Create the EGL data parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785 14.4.2 Create and customize a page template . . . . . . . . . . . . . . . . . . . . 799 14.4.3 Create the Faces JSPs using the Web Diagram tool . . . . . . . . . . 802 14.4.4 Add EGL components to the Faces JSPs . . . . . . . . . . . . . . . . . . . 806 14.5 Import and run the sample Web application . . . . . . . . . . . . . . . . . . . . . 816 14.5.1 Import the EGL Web application sample. . . . . . . . . . . . . . . . . . . . 816 14.5.2 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816 14.5.3 Generate Java from EGL source . . . . . . . . . . . . . . . . . . . . . . . . . 817 14.5.4 Run the sample EGL Web application . . . . . . . . . . . . . . . . . . . . . 818 14.6 Considerations for exporting an EGL project . . . . . . . . . . . . . . . . . . . . 820 14.6.1 Reduce the file size of the Project Interchange file . . . . . . . . . . . . 821 14.6.2 Manually adding the runtime libraries after migration . . . . . . . . . . 822 14.6.3 Export WAR/EAR with source . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823 Chapter 15. Develop Web applications using EJBs. . . . . . . . . . . . . . . . . 827 15.1 Introduction to Enterprise JavaBeans . . . . . . . . . . . . . . . . . . . . . . . . . . 828 15.1.1 What is new. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828 15.1.2 Enterprise JavaBeans overview . . . . . . . . . . . . . . . . . . . . . . . . . . 828 15.1.3 EJB server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 831 15.1.4 EJB container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832 15.1.5 EJB components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 834

xii

Rational Application Developer V6 Programming Guide

15.2 RedBank sample application overview . . . . . . . . . . . . . . . . . . . . . . . . . 840 15.3 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844 15.3.1 Required software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844 15.3.2 Create and configure the EJB projects . . . . . . . . . . . . . . . . . . . . . 844 15.3.3 Create an EJB project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845 15.3.4 Configure the EJB projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849 15.3.5 Import BankBasicWeb Project . . . . . . . . . . . . . . . . . . . . . . . . . . . 853 15.3.6 Set up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854 15.3.7 Configure the data source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856 15.4 Develop an EJB application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858 15.4.1 Create the entity beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859 15.4.2 Create the entity relationships. . . . . . . . . . . . . . . . . . . . . . . . . . . . 872 15.4.3 Customize the entity beans and add business logic . . . . . . . . . . . 880 15.4.4 Creating custom finders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 890 15.4.5 Object-relational mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 892 15.4.6 Implement the session facade . . . . . . . . . . . . . . . . . . . . . . . . . . . 901 15.5 Testing EJB with the Universal Test Client . . . . . . . . . . . . . . . . . . . . . . 915 15.6 Adapting the Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 919 Chapter 16. Develop J2EE application clients . . . . . . . . . . . . . . . . . . . . . 925 16.1 Introduction to J2EE application clients. . . . . . . . . . . . . . . . . . . . . . . . . 926 16.2 Overview of the sample application. . . . . . . . . . . . . . . . . . . . . . . . . . . . 928 16.3 Preparing for the sample application. . . . . . . . . . . . . . . . . . . . . . . . . . . 931 16.3.1 Import the base enterprise application sample . . . . . . . . . . . . . . . 932 16.3.2 Set up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933 16.3.3 Configure the data source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 934 16.3.4 Test the imported code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936 16.4 Develop the J2EE application client . . . . . . . . . . . . . . . . . . . . . . . . . . . 936 16.4.1 Create the J2EE application client projects. . . . . . . . . . . . . . . . . . 937 16.4.2 Configure the J2EE application client projects . . . . . . . . . . . . . . . 938 16.4.3 Import the graphical user interface and control classes . . . . . . . . 939 16.4.4 Create the BankDesktopController class . . . . . . . . . . . . . . . . . . . 940 16.4.5 Complete the BankDesktopController class . . . . . . . . . . . . . . . . . 942 16.4.6 Register the BankDesktopController class as the Main class . . . . 946 16.5 Test the J2EE application client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946 16.6 Package the application client project . . . . . . . . . . . . . . . . . . . . . . . . . . 949 Chapter 17. Develop Web Services applications . . . . . . . . . . . . . . . . . . . 951 17.1 Introduction to Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952 17.1.1 Service-oriented architecture (SOA) . . . . . . . . . . . . . . . . . . . . . . . 952 17.1.2 Web Services as an SOA implementation . . . . . . . . . . . . . . . . . . 953 17.1.3 Related Web Services standards . . . . . . . . . . . . . . . . . . . . . . . . . 955 17.2 Web Services tools in Application Developer . . . . . . . . . . . . . . . . . . . . 957

Contents

xiii

17.2.1 Creating a Web Service from existing resources . . . . . . . . . . . . . 957 17.2.2 Creating a skeleton Web Service . . . . . . . . . . . . . . . . . . . . . . . . . 958 17.2.3 Client development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958 17.2.4 Testing tools for Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . 959 17.3 Preparing for the samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959 17.3.1 Import the sample code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959 17.3.2 Enable the Web Services Development capability . . . . . . . . . . . . 960 17.3.3 Set up the sample back-end database . . . . . . . . . . . . . . . . . . . . . 961 17.3.4 Add Cloudscape JDBC driver (JAR) to the project . . . . . . . . . . . . 962 17.3.5 Define a server to test the application . . . . . . . . . . . . . . . . . . . . . . 963 17.3.6 Test the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963 17.4 Create a Web Service from a JavaBean . . . . . . . . . . . . . . . . . . . . . . . . 964 17.4.1 Create a Web Service using the Web Service wizard. . . . . . . . . . 964 17.4.2 Resources generated by the Web Services wizard . . . . . . . . . . . 968 17.4.3 Test the Web Service using the Web Services Explorer. . . . . . . . 971 17.4.4 Generate and test the client proxy . . . . . . . . . . . . . . . . . . . . . . . . 973 17.4.5 Monitor the Web Service using the TCP/IP Monitor . . . . . . . . . . . 976 17.5 Create a Web Service from an EJB . . . . . . . . . . . . . . . . . . . . . . . . . . . 980 17.6 Web Services security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 980 17.7 Publish a Web Service using UDDI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 982 Chapter 18. Develop portal applications. . . . . . . . . . . . . . . . . . . . . . . . . . 985 18.1 Introduction to portals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986 18.1.1 Portal concepts and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 986 18.1.2 IBM WebSphere Portal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 989 18.1.3 IBM Rational Application Developer . . . . . . . . . . . . . . . . . . . . . . . 989 18.2 Developing applications for WebSphere Portal. . . . . . . . . . . . . . . . . . . 992 18.2.1 Portal samples and tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 992 18.2.2 Development strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993 18.2.3 Portal tools for developing portals . . . . . . . . . . . . . . . . . . . . . . . . . 996 18.2.4 Portal tools for developing portlets . . . . . . . . . . . . . . . . . . . . . . . 1002 18.2.5 Portal tools for testing and debugging portlets . . . . . . . . . . . . . . 1016 18.2.6 Portal tools for deploying and managing portlets . . . . . . . . . . . . 1020 18.2.7 Enterprise Application Integration Portal Tools . . . . . . . . . . . . . . 1022 18.2.8 Coexistence and migration of tools and applications . . . . . . . . . 1023 18.3 Portal development scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025 18.3.1 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025 18.3.2 Create a portal project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026 18.3.3 Add and modify a portal page . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027 18.3.4 Create and modify two portlets . . . . . . . . . . . . . . . . . . . . . . . . . . 1030 18.3.5 Add portlets to a portal page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033 18.3.6 Run the project in the test environment . . . . . . . . . . . . . . . . . . . 1037

xiv

Rational Application Developer V6 Programming Guide

Part 3. Test and debug applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1041 Chapter 19. Servers and server configuration . . . . . . . . . . . . . . . . . . . . 1043 19.1 Introduction to server configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 1044 19.1.1 Supported test server environments . . . . . . . . . . . . . . . . . . . . . . 1045 19.1.2 Local vs. remote test environments . . . . . . . . . . . . . . . . . . . . . . 1046 19.1.3 Commands to manage test servers . . . . . . . . . . . . . . . . . . . . . . 1046 19.2 Configure a WebSphere V6 Test Environment . . . . . . . . . . . . . . . . . . 1046 19.2.1 Understanding WebSphere Application Server V6.0 profiles . . . 1047 19.2.2 WebSphere Application Server V6 installation . . . . . . . . . . . . . . 1050 19.2.3 WebSphere Application Server V6 profile creation . . . . . . . . . . . 1051 19.2.4 Define a new server in Rational Application Developer . . . . . . . 1057 19.2.5 Verify the server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061 19.2.6 Customize a server in Rational Application Developer . . . . . . . . 1062 19.3 Add a project to a server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1064 19.3.1 Considerations for adding a project to a server . . . . . . . . . . . . . 1064 19.3.2 Add a project to a server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065 19.4 Remove a project from a server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066 19.4.1 Remove a project via Rational Application Developer . . . . . . . . 1066 19.4.2 Remove a project via WebSphere Administrative Console. . . . . 1067 19.5 Publish application changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068 19.6 Configure application and server resources . . . . . . . . . . . . . . . . . . . . 1069 19.6.1 Configure application resources . . . . . . . . . . . . . . . . . . . . . . . . . 1069 19.6.2 Configure server resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078 19.6.3 Configure messaging resources . . . . . . . . . . . . . . . . . . . . . . . . . 1079 19.6.4 Configure security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079 19.7 TCP/IP Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079 Chapter 20. JUnit and component testing . . . . . . . . . . . . . . . . . . . . . . . 1081 20.1 Introduction to application testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1082 20.1.1 Test concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1082 20.1.2 Benefits of unit and component testing . . . . . . . . . . . . . . . . . . . . 1085 20.1.3 Eclipse Hyades . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086 20.2 JUnit testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087 20.2.1 JUnit fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087 20.2.2 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089 20.2.3 Create the JUnit test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089 20.2.4 Run the JUnit test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1098 20.3 Automated component testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1102 20.3.1 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1102 20.3.2 Create a test project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1103 20.3.3 Create a Java component test . . . . . . . . . . . . . . . . . . . . . . . . . . 1103 20.3.4 Complete the component test code . . . . . . . . . . . . . . . . . . . . . . 1107

Contents

xv

20.3.5 Run the component test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1110 20.4 Web application testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1112 20.4.1 Preparing for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1113 20.4.2 Create a Java project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1113 20.4.3 Create (record) a test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1113 20.4.4 Edit the test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115 20.4.5 Generate an executable test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115 20.4.6 Create a deployment definition . . . . . . . . . . . . . . . . . . . . . . . . . . 1116 20.4.7 Run the test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1117 20.4.8 Analyze the test results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1118 Chapter 21. Debug local and remote applications . . . . . . . . . . . . . . . . . 1121 21.1 Introduction to the debug tooling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1122 21.1.1 Summary of new Version 6 features . . . . . . . . . . . . . . . . . . . . . . 1122 21.1.2 Supported languages and environments . . . . . . . . . . . . . . . . . . 1124 21.1.3 General functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1124 21.1.4 Drop-to-frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1126 21.1.5 View Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1127 21.1.6 XSLT debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1128 21.2 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1131 21.3 Debug a Web application on a local server. . . . . . . . . . . . . . . . . . . . . 1132 21.3.1 Set breakpoints in a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1132 21.3.2 Set breakpoints in a JSP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1135 21.3.3 Start the application for debugging . . . . . . . . . . . . . . . . . . . . . . . 1136 21.3.4 Run the application in the debugger . . . . . . . . . . . . . . . . . . . . . . 1136 21.3.5 Debug view with stack frames. . . . . . . . . . . . . . . . . . . . . . . . . . . 1141 21.3.6 Debug functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1141 21.3.7 Breakpoints view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1142 21.3.8 Watch variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1142 21.3.9 Inspect variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143 21.3.10 Evaluate an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143 21.3.11 Debug a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1145 21.4 Debug a Web application on a remote server . . . . . . . . . . . . . . . . . . . 1145 21.4.1 Export the BankBasicWeb project to a WAR file. . . . . . . . . . . . . 1145 21.4.2 Deploy the BankBasicWeb.war . . . . . . . . . . . . . . . . . . . . . . . . . . 1146 21.4.3 Install the IBM Rational Agent Controller . . . . . . . . . . . . . . . . . . 1147 21.4.4 Configure debug on remote WebSphere Application Server . . . 1147 21.4.5 Attach to the remote server in Rational Application Developer . . 1148 21.4.6 Debug the application on the remote server . . . . . . . . . . . . . . . . 1151 Part 4. Deploy and profile applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153 Chapter 22. Build applications with Ant . . . . . . . . . . . . . . . . . . . . . . . . . 1155 22.1 Introduction to Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1156

xvi

Rational Application Developer V6 Programming Guide

22.1.1 Ant build files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1156 22.1.2 Ant tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1157 22.2 New features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1157 22.2.1 Code Assist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1158 22.2.2 Code snippets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1159 22.2.3 Format an Ant script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1163 22.2.4 Define format of an Ant script . . . . . . . . . . . . . . . . . . . . . . . . . . . 1164 22.2.5 Problem view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1166 22.3 Build a simple Java application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1167 22.3.1 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1168 22.3.2 Create a build file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1169 22.3.3 Project definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1171 22.3.4 Global properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1171 22.3.5 Build targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1171 22.3.6 Run Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1173 22.3.7 Ant Log Console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1176 22.3.8 Rerun Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1177 22.3.9 Forced build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1177 22.3.10 Classpath problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1178 22.3.11 Run the sample application to verify the Ant build . . . . . . . . . . 1178 22.4 Build a J2EE application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1178 22.4.1 J2EE application deployment packaging . . . . . . . . . . . . . . . . . . 1179 22.4.2 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1179 22.4.3 Create the build script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1180 22.4.4 Run the Ant J2EE application build . . . . . . . . . . . . . . . . . . . . . . . 1183 22.5 Run Ant outside of Application Developer. . . . . . . . . . . . . . . . . . . . . . 1185 22.5.1 Prepare for the headless build . . . . . . . . . . . . . . . . . . . . . . . . . . 1186 22.5.2 Run the headless Ant build script . . . . . . . . . . . . . . . . . . . . . . . . 1187 Chapter 23. Deploy enterprise applications . . . . . . . . . . . . . . . . . . . . . . 1189 23.1 Introduction to application deployment . . . . . . . . . . . . . . . . . . . . . . . . 1190 23.1.1 Common deployment considerations . . . . . . . . . . . . . . . . . . . . . 1190 23.1.2 J2EE application components and deployment modules . . . . . . 1191 23.1.3 Java and WebSphere class loader . . . . . . . . . . . . . . . . . . . . . . . 1191 23.1.4 Deployment descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1196 23.1.5 WebSphere deployment architecture . . . . . . . . . . . . . . . . . . . . . 1199 23.2 Prepare for the sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1212 23.2.1 Review the deployment scenarios . . . . . . . . . . . . . . . . . . . . . . . 1213 23.2.2 Install prerequisite software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1213 23.2.3 Import the sample application Project Interchange file . . . . . . . . 1214 23.2.4 Set up the sample database . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1215 23.3 Package the application for deployment . . . . . . . . . . . . . . . . . . . . . . . 1218 23.3.1 Packaging recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . 1218

Contents

xvii

23.3.2 Generate the EJB to RDB mapping . . . . . . . . . . . . . . . . . . . . . . 1218 23.3.3 Customize the deployment descriptors . . . . . . . . . . . . . . . . . . . . 1220 23.3.4 Remove the Enhanced EAR datasource . . . . . . . . . . . . . . . . . . 1221 23.3.5 Generate the deploy code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1222 23.3.6 Export the EAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1222 23.4 Deploy the enterprise application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1224 23.4.1 Configure the data source in WebSphere Application Server . . . 1225 23.4.2 Deploy the EAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1229 23.5 Verify the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1230 Chapter 24. Profile applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1237 24.1 Introduction to profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1238 24.1.1 Profiling features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1238 24.1.2 Profiling architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1242 24.1.3 Profiling and Logging perspective . . . . . . . . . . . . . . . . . . . . . . . . 1244 24.1.4 Profiling sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1245 24.2 Prepare for the profiling sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1246 24.2.1 Prerequisites hardware and software . . . . . . . . . . . . . . . . . . . . . 1247 24.2.2 Enable the Profiling and Logging capability . . . . . . . . . . . . . . . . 1247 24.2.3 Import the sample project interchange file . . . . . . . . . . . . . . . . . 1248 24.2.4 Publish and run sample application . . . . . . . . . . . . . . . . . . . . . . 1249 24.3 Profile the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1249 24.3.1 Start server in profile mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1249 24.3.2 Collect profile information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1253 24.3.3 Analysis of code coverage information . . . . . . . . . . . . . . . . . . . . 1253 Part 5. Team development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1255 Chapter 25. Rational ClearCase integration . . . . . . . . . . . . . . . . . . . . . . 1257 25.1 Introduction to IBM Rational ClearCase . . . . . . . . . . . . . . . . . . . . . . . 1258 25.1.1 IBM Rational Application Developer ClearCase overview . . . . . 1258 25.1.2 IBM Rational ClearCase terminology . . . . . . . . . . . . . . . . . . . . . 1259 25.1.3 IBM Rational ClearCase LT installation . . . . . . . . . . . . . . . . . . . 1260 25.1.4 IBM Rational Application Developer integration for ClearCase. . 1260 25.2 Integration scenario overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1263 25.3 ClearCase setup for a new project . . . . . . . . . . . . . . . . . . . . . . . . . . . 1264 25.3.1 Enable Team capability in preferences . . . . . . . . . . . . . . . . . . . . 1264 25.3.2 Create new ClearCase project . . . . . . . . . . . . . . . . . . . . . . . . . . 1265 25.3.3 Join a ClearCase project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1268 25.3.4 Create a Web project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1274 25.3.5 Add a project to ClearCase source control . . . . . . . . . . . . . . . . . 1274 25.4 Development scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1277 25.4.1 Developer 1 adds a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1277 25.4.2 Developer 1 delivers work to the integration stream . . . . . . . . . . 1279

xviii

Rational Application Developer V6 Programming Guide

25.4.3 25.4.4 25.4.5 25.4.6 25.4.7 25.4.8 25.4.9

Developer 1 makes a baseline . . . . . . . . . . . . . . . . . . . . . . . . . . 1282 Developer 2 joins the project. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1284 Developer 2 imports projects into Application Developer . . . . . . 1287 Developer 2 modifies the servlet. . . . . . . . . . . . . . . . . . . . . . . . . 1289 Developer 2 delivers work to the integration stream . . . . . . . . . . 1292 Developer 1 modifies the servlet. . . . . . . . . . . . . . . . . . . . . . . . . 1293 Developer 1 delivers new work to the integration stream . . . . . . 1294

Chapter 26. CVS integration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1299 26.1 Introduction to CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1300 26.1.1 CVS features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1300 26.1.2 New V6 features for team development . . . . . . . . . . . . . . . . . . . 1301 26.2 CVSNT Server implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1301 26.2.1 CVS Server installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1302 26.2.2 CVS Server repository configuration . . . . . . . . . . . . . . . . . . . . . . 1303 26.2.3 Create the Windows users and groups used by CVS . . . . . . . . . 1306 26.2.4 Verify the CVSNT installation . . . . . . . . . . . . . . . . . . . . . . . . . . . 1307 26.2.5 Create CVS users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1308 26.3 CVS client configuration for Application Developer . . . . . . . . . . . . . . . 1309 26.3.1 Configure CVS Team Capabilities . . . . . . . . . . . . . . . . . . . . . . . 1309 26.3.2 Access the CVS Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1310 26.4 Configure CVS in Rational Application Developer . . . . . . . . . . . . . . . 1312 26.4.1 Configure Rational Application Developer CVS preferences . . . 1312 26.5 Development scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1321 26.5.1 Create and share the project (step 1 - cvsuser1) . . . . . . . . . . . . 1322 26.5.2 Add a shared project to the workspace (step 2 - cvsuser2) . . . . 1327 26.5.3 Modifying the Servlet (step 2 - cvsuser1) . . . . . . . . . . . . . . . . . . 1332 26.5.4 Synchronize with repository (step 3 - cvsuser1) . . . . . . . . . . . . . 1333 26.5.5 Parallel development (step 4 - cvsuser1 and cvsuser2) . . . . . . . 1335 26.5.6 Versioning (step 5- cvsuser1) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1342 26.6 CVS resource history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1343 26.7 Comparisons in CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1344 26.7.1 Comparing workspace file with repository. . . . . . . . . . . . . . . . . . 1345 26.7.2 Comparing two revisions in repository . . . . . . . . . . . . . . . . . . . . 1347 26.8 Annotations in CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1348 26.9 Branches in CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1350 26.9.1 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1350 26.9.2 Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1354 26.9.3 Refreshing server-defined branches . . . . . . . . . . . . . . . . . . . . . . 1357 26.10 Work with patches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1360 26.11 Disconnecting a project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1360 26.12 Synchronize perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1361 26.12.1 Custom configuration of resource synchronization . . . . . . . . . . 1362

Contents

xix

26.12.2 Schedule synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1367 Part 6. Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1369 Appendix A. IBM product installation and configuration tips. . . . . . . . 1371 IBM Rational Application Developer V6 installation . . . . . . . . . . . . . . . . . . . 1372 Rational Application Developer installation . . . . . . . . . . . . . . . . . . . . . . . 1372 WebSphere Portal V5.0 Test Environment installation . . . . . . . . . . . . . . 1376 WebSphere Portal V5.1 Test Environment installation . . . . . . . . . . . . . . 1377 Rational Application Developer Product Updater - Interim Fix 0004 . . . . 1380 IBM Rational Agent Controller V6 installation . . . . . . . . . . . . . . . . . . . . . . . 1382 IBM Rational ClearCase LT installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1385 IBM DB2 Universal Database V8.2 installation . . . . . . . . . . . . . . . . . . . . . . 1387 IBM WebSphere Application Server V6 installation . . . . . . . . . . . . . . . . . . . 1387 WebSphere Application Server messaging configuration . . . . . . . . . . . . . . 1389 Configure the service bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1390 Configure the bus members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1390 Configure the destinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1390 Verify the messaging engine startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1391 Configure JMS connection queue factory . . . . . . . . . . . . . . . . . . . . . . . . 1391 Configure the destination JMS queue . . . . . . . . . . . . . . . . . . . . . . . . . . . 1392 Configuration of a JMS activation specification. . . . . . . . . . . . . . . . . . . . 1392 Appendix B. Additional material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1395 Locating the Web material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1396 System requirements for downloading the Web material . . . . . . . . . . . . 1396 Unpack the 6449code.zip. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1396 Description of sample code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1396 Import sample code from a Project Interchange file . . . . . . . . . . . . . . . . . . . 1398 Related publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1401 IBM Redbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1401 Other publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1402 Online resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1402 How to get IBM Redbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1404 Help from IBM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1404 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1405

xx

Rational Application Developer V6 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 information contains sample application programs in source language, which illustrates programming techniques on various operating platforms. You may copy, modify, and distribute these sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. You may copy, modify, and distribute these sample programs in any form without payment to IBM for the purposes of developing, using, marketing, or distributing application programs conforming to IBM's application programming interfaces.

Copyright IBM Corp. 2005. All rights reserved.

xxi

TrademarksThe following terms are trademarks of the International Business Machines Corporation in the United States, other countries, or both: AIX Balance ClearCase MultiSite ClearCase Cloudscape DB2 Universal Database DB2 developerWorks Informix IBM ibm.com IMS iSeries Lotus Notes Lotus Notes OS/390 OS/400 Rational Rose Rational Unified Process Rational Redbooks Redbooks (logo) RUP S/390 ThinkCentre VisualAge VisualGen WebSphere Workplace Workplace Web Content Management XDE z/OS zSeries

The following terms are trademarks of other companies: Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. Intel, Intel Inside (logos), MMX, and Pentium are trademarks of Intel Corporation in the United States, other countries, or both. UNIX is a registered trademark of The Open Group in the United States and other countries. Linux is a trademark of Linus Torvalds in the United States, other countries, or both. Other company, product, and service names may be trademarks or service marks of others.

xxii

Rational Application Developer V6 Programming Guide

PrefaceIBM Rational Application Developer V6.0 is the full function Eclipse 3.0 based development platform for developing Java 2 Platform Standard Edition (J2SE) and Java 2 Platform Enterprise Edition (J2EE) applications with a focus on applications to be deployed to IBM WebSphere Application Server and IBM WebSphere Portal. Rational Application Developer provides integrated development tools for all development roles, including Web developers, Java developers, business analysts, architects, and enterprise programmers. This IBM Redbook is a programming guide that highlights the features and tooling included with IBM Rational Application Developer V6.0. Many of the chapters provide working examples that demonstrate how to use the tooling to develop applications as well as achieve the benefits of visual and rapid Web development. This book consists of six parts: Introduction to Rational Application Developer Develop applications Test and debug applications Deploy and profile applications Team development Appendixes

The team that wrote this redbookThis redbook was produced by a team of specialists from around the world working at the International Technical Support Organization, Raleigh Center.

Copyright IBM Corp. 2005. All rights reserved.

xxiii

Figure 1 IBM Redbook team (top, l-r: Neil Weightman, Fabio Ferraz, Richard Raszka, Juha Nevalainen; bottom, l-r: Hari Kanangi, John Ganci, Nicolai Nielsen, Kiriya Keat)

John Ganci is a Consulting IT Specialist at the IBM ITSO, Raleigh Center, USA. John has 15 years of experience in application design, development, testing, and consulting. His areas of expertise include e-business integration, WebSphere Application Server, e-commerce, portals, pervasive computing, technical team leadership, Linux, and J2EE programming. Daniel Farrell is a Certified Specialist in the IBM Software Group USA. He has a Masters degree in Computer Science from Regis University and is currently pursuing a PhD from Clemson in Adult Education and Human Resource Studies. He has 20 years of experience working with Informix and related database technologies, and more recently has been focusing on IBM EGL and supporting tooling.

xxiv

Rational Application Developer V6 Programming Guide

Fabio Ferraz is the Chief Consultant for Advus Corp, So Paulo, Brazil. He has 12 years of experience in the IT field, with eight of those dedicated to e-business. Ed Gondek is a Product Manager in the USA with IBM Software Group Rational products division. He has 25 years of Information Systems and software management experience with expertise in 4GLs, Web-based application design, Web analytics, business intelligence tooling, and software product delivery. Hari Kanangi is a Senior Technical Consultant for Stratus Solutions, Inc. He has nine years of industry experience. Over the past six years, Hari has focused on WebSphere, J2EE, and Java-based technologies. His expertise includes architecting, designing, developing, and deploying J2EE-based solutions. He is a Sun-certified Java Programmer, architect, and a WebSphere-certified specialist. Kiriya Keat is an IT Specialist in Australia with IBM Global Services. He has five years of experience in the Web development field. His areas of expertise include e-business integration, application architecture and development, technical team leadership, and WebSphere solutions. George Kroner is a Co-op IT Specialist at the IBM ITSO Center in Raleigh, North Carolina. He is currently pursuing a Bachelor of Science degree in Information Sciences and Technology at Pennsylvania State University. His interests include Web applications, wireless/mobile computing, and intelligent interfaces. Juha Nevalainen is an Consulting IT Specialist for Rational Technical Sales with IBM Finland. His areas of expertise include Rational brand software products, WebSphere Commerce, e-business, and systems integration. Nicolai Nielsen is an Advisory IT Specialist with IBM Global Services, Denmark. He has nine years of experience in the fields of consulting, application development, and systems integration. Nicolai holds a degree in engineering from the Technical University of Denmark. He has written extensively about WebSphere Commerce, J2EE application development, and has worked on several WebSphere Commerce projects over the last three years. Richard Raszka is a Senior IT Specialist in IBM Global Services, Application Management Services, Australia. He has 19 years of IT experience in the fields of application development, systems integration (particularly of e-business/e-commerce solutions), project planning, compiler development, configuration management, graphics and CAD/CAM development, simulation, and agent-oriented artificial intelligence. He holds degrees in Mechanical Engineering, Mathematical and Computer Science from the University of Adelaide and a Masters of Technology Management from Monash University in Melbourne. His areas of expertise include end-to-end systems integration, application design including patterns, application architecture, and development,

Preface

xxv

technical team leadership, e-business solutions, WebSphere Application Server, UNIX, J2EE architecture, and Java development. Neil Weightman is a Technical Instructor in the United Kingdom. He has 15 years of experience in the software development field. He holds a degree in Physics from Imperial College, University of London, and a masters in Scientific Computing from South Bank University, London. His areas of expertise include J2EE component development, Web services development, and best practices. Thanks to the following people for their contributions to this project: Ueli Wahli, Ian Brown, Fabio Ferraz, Maik Schumacher, Henrik Sjostrand who wrote the previous redbook edition, WebSphere Studio Application Developer Version 5 Programming Guide, SG24-6957 Special thanks to Eric Erpenbach from the IBM WebSphere Technology and Training organization for providing early training materials on IBM Rational Application Developer V6.0, which was a tremendous help in ramping up on the new features for many topics found in this book Beverly DeWitt, Rational Application Developer Product Manager, IBM Toronto, Canada Geni Hutton, Rational Application Developer Product Manager, IBM Toronto, Canada Todd Britton, Manager for IBM Rational Application Developer Tools Development, IBM Raleigh, USA Kate Price, Rational Application Developer Information Development, IBM Toronto, Canada Leigh Davidson, Rational Application Developer Information Development Editor, IBM Toronto, Canada Tim Deboer, IBM WebSphere Tools, IBM Toronto, Canada Prem Lall, IT Specialist for IBM Global Services, IBM Gaithersburg, USA Chris Feldhacker, Principal Financial Group

Become a published authorJoin us for a two- to six-week residency program! Help write an IBM Redbook dealing with specific products or solutions, while getting hands-on experience with leading-edge technologies. You'll team with IBM technical professionals, Business Partners and/or customers.

xxvi

Rational Application Developer V6 Programming Guide

Your efforts will help increase product acceptance and customer satisfaction. As a bonus, you'll develop a network of contacts in IBM development labs, and increase your productivity and marketability. Find out more about the residency program, browse the residency index, and apply online at:ibm.com/redbooks/residencies.html

Comments welcomeYour comments are important to us! We want our Redbooks to be as helpful as possible. Send us your comments about this or other Redbooks in one of the following ways: Use the online Contact us review redbook form found at:ibm.com/redbooks

Send your comments in an email to:[email protected]

Mail your comments to: IBM Corporation, International Technical Support Organization Dept. HZ8 Building 662 P.O. Box 12195 Research Triangle Park, NC 27709-2195

Summary of changesThis section describes the technical changes made in this edition of the book and in previous editions. This edition may also include minor corrections and editorial changes that are not identified. Summary of Changes for SG24-6449-00 for the Rational Application Developer V6 Programming Guide

June 2005, First EditionThis book is a major rewrite ofWebSphere Studio Application Developer Version 5 Programming Guide, SG24-6957. The previous book was based on Application Developer Version 5; this book is based on Version 6.

Preface

xxvii

This revision reflects the addition, deletion, or modification of new and changed information described below.

New informationBroaden appeal Improves user assistance and ease of learning Progressive disclosure of tools Raise productivity Rapid Web and Portal application development Rapid deployment to WebSphere Application Server V6.0 Extended integration Integration of Rational technology to enhance the application development lifecycle and raise productivity Enhance portal as a first-class deployment target Maintain standards and middleware support Java 2 Platform Enterprise Edition V1.4 specification compliance Support for many new integrated test servers including WebSphere Application Server V6.0/V5.x, and WebSphere Portal V5.0.2.2 New and enhanced tooling (Web Services, EGL, Visual UML, portal, Struts, JSF, SDO, etc.).

Changed informationGeneral update of existing information to Version 6

Deleted informationDeveloping Web applications with database access using DB beans. The preferred method of database access is Service Data Objects (SDO).

xxviii

Rational Application Developer V6 Programming Guide

Part 1

Part

1

Introduction to Rational Application Developer

Copyright IBM Corp. 2005. All rights reserved.

1

2

Rational Application Developer V6 Programming Guide

1

Chapter 1.

IntroductionIBM Rational Application Developer V6.0 is the full function development platform for developing Java 2 Platform Standard Edition (J2SE) and Java 2 Platform Enterprise Edition (J2EE) applications with a focus on applications to be deployed to IBM WebSphere Application Server and IBM WebSphere Portal. This chapter contains an introduction to the concepts, packaging, and features of IBM Rational Application Developer V6.0 and IBM Rational Web Developer V6.0 products. The chapter is organized into the following sections: Introduction and concepts Product packaging Product features Sample code Note: Although this chapter does contain information on both IBM Rational Application Developer V6.0 and IBM Rational Web Developer V6.0, the majority of the chapters and samples found in this book were only tested with IBM Rational Application Developer V6.0.

Copyright IBM Corp. 2005. All rights reserved.

3

1.1 Introduction and conceptsThis section provides an introduction to the Rational Software Development Platform, Eclipse, Rational Application Developer, and Rational Web Developer. Rational products help your business or organization manage the entire software development process. Software modelers, architects, developers, and testers can use the same team-unifying Rational Software Development Platform tooling to be more efficient in exchanging assets, following common processes, managing change and requirements, ma