Kick-start your Java apps, Part 1: Free software, fast development

Skill Level: Intermediate Sing Li ( Author Wrox Press

27 Feb 2006 To create, test, and deploy a Web-based application or Web service rapidly, you need a proven relational database, a standards-compliant Web application server, and a flexible IDE. Ideally, all these software packages are production-tested, simple to obtain, easy to use, and well integrated with one another. This tutorial shows you how to use IBM-backed open source and free software to kick-start your Java™ Web-based application development. You'll learn exactly where to download such components, install them, and get them working for you today.

Section 1. Before you start
Combine the proven power of the industrial-strength DB2® database with the versatility of the J2EE 1.4 compatible WebSphere® Application Server, then throw in the popular open source Eclipse IDE -- and you can have a highly productive environment to create, test, and deploy Web-based applications and Web services. This is not a secret, and professionals in large IT projects have been enjoying this proven collection of software for years. But until now, the development community at large has not had general access to these tools. Times have changed, though, and today full-featured editions of the servers and IDE in this collection are only a download away -- free of charge and free of license fees -- with full support from IBM. Java developers can now freely use the open source Eclipse IDE to create and test applications and Web services and then install them to WebSphere Application Server Community Edition (referred to throughout this tutorial as Application Server) and DB2 Express-C 9 for production deployment.

Free software, fast development © Copyright IBM Corporation 1994, 2006. All rights reserved.

Page 1 of 60


About this tutorial
This tutorial takes you along the shortest path to getting these software components -- called the Kick-start your Java apps suite -- downloaded and working, letting you discover their infinite possibilities while creating your next programming masterpiece. It assists you in installing and setting up the components and reveals how they are designed to work with one another. Toward this goal, the tutorial does not attempt to cover all possible features or configuration options available for the individual packages. You'll be able to discover each product's rich feature set at your own pace as you continue exploration and development. The Kick-start combo
With the Kick-start your Java apps suite, IBM has put together a powerful combination of freely available software components for data, deployment, and development: • • • DB2 Express-C 9 database server WebSphere Application Server Community Edition The Eclipse IDE

You're not locked in to using these packages in combination; each works with a variety of other open-standards based components. You can use Eclipse with other (even non-Java) application servers and other databases. Application Server doesn't require either DB2 Express-C 9 or Eclipse. And DB2 Express-C 9 can fit into development and deployment environments other than Eclipse and Application Server. But, in ways you'll understand fully from this tutorial, using the whole, tightly integrated suite can gain you a wealth of advantages.

This tutorial guides you through: • Downloading and installing DB2 Express-C 9 • Creating databases and manipulating data with tools in DB2 Express-C 9 • Downloading and installing Application Server • Managing Application Server through the Web console • Connecting Application Server to DB2 Express-C 9 using a JCA 1.5 connector • Downloading and installing Eclipse • Installing the Eclipse Web Tools Platform (WTP) server adapter for Application Server (formerly called the Application Server plug-in for Eclipse) • Managing, browsing, and editing DB2 Express-C 9 data through the Eclipse IDE

Free software, fast development Page 2 of 60

© Copyright IBM Corporation 1994, 2006. All rights reserved.


• Testing Web applications in Eclipse with embedded control of Application Server instances • Rapidly developing and testing a JSP/JSTL Web application in Eclipse, with data access to DB2 Express-C 9, and deploying it to Application Server • Configuring Application Server as a general Web server on the Internet By the end of the tutorial, you'll have hands-on working experience with all the software tools and have a simple data-driven Java application deployed on Application Server.

You should be familiar with Java development in general and server-side Java development specifically. This tutorial assumes that you understand the general operations of a relational database and are familiar with basic J2EE concepts, such as deployment descriptors and WAR archives. Experience working with an application server and relational database is beneficial but not mandatory.

System requirements
To follow along and try out the code for this tutorial, you need a working installation of Sun's JDK 1.4.2_12 or the IBM 1.5.0 SR3 JDK. The recommended system configuration for trying out the tutorial is: • A system supporting the JDK/JRE listed above with at least 1GB of main memory (2GB recommended) • At least 900MB of disk space to install the software components and examples The instructions in the tutorial are based on a Windows operating system. All of the tools covered in the tutorial also work on Linux® and UNIX® systems.

Section 2. Overview
The Kick-start your Java apps suite of software includes the following products and versions, which are designed to work well together: • A database server: DB2 Express-C (currently at UDB 9.1 level)

Free software, fast development © Copyright IBM Corporation 1994, 2006. All rights reserved.

Page 3 of 60

and debug in the Eclipse IDE As Figure 1 illustrates. In addition to working with them together as a concept-to-production toolkit. and field names. DB2 Express-C 9 integrates with the Eclipse IDE to provide you with easy access to your database content as well as metadata information. and DB2 Express-C 9 working together Code. For • An application server: WebSphere Application Server Community Edition (currently release 1. table.1. you can access DB2 Express-C 9 through C/C++. Free software.1. You can control instances of Application Server from the Eclipse IDE to deploy and test your application components rapidly. and debug your Java applications using the Eclipse IDE. Figure 1 illustrates how these products fit together for server-side Java application development: Figure 1.1 for Application Server) You can download all of these packages without cost or license fees. Python. . among others. fast development Page 4 of 60 © Copyright IBM Corporation 1994.developerWorks® ibm. 2006. Ruby. as you can see in Figure 1.1) • An IDE: Eclipse (currently version 3. All rights reserved. test.2 for use with the WTP server adapter V1. such as schema. test. Application Server. Eclipse. and Perl APIs. you can use each of these products alone or with a myriad of available interfacing technology. you can write.

when building very large database systems. open source. The robust. You can use Eclipse and Application Server with proven. International enterprises use DB2 today to maintain some of the largest databases on servers that run around the clock. Introducing DB2 Express-C 9 As a member of the DB2 Universal Database™ family. Users can access your application through a browser pointed to the Application Server. 100% JDBC driver. you can deploy it into production running inside Application Server. servlets. high-performance type 4. DB2 Express-C 9 is the free-of-charge edition of the modern version of a "very big iron" RDBMS. Page 5 of 60 . Section 3. lightweight frameworks such as the Spring Framework and Hibernate.5 resource adapters and can make use of the DB2 Express-C 9 JDBC driver to provide data persistence for any hosted application. If you are already committed to a different database that you'd like to use with Eclipse and/or Application Server in this tutorial. DB2 Express-C 9 supports Java-based data access through JDBC. install. hosted on Application Server. Application Server also doubles as a general-purpose Web server for static HTML pages and graphic files. and the following three sections show you how to download. fast development © Copyright IBM Corporation 1994. you can have a cluster of multiple machines working together to run a Free software. Application Server is a J2EE 1. and Enterprise JavaBeans (EJB). This driver works very well with 100% Java applications requiring relational database management system (RDBMS) access. This section introduces DB2 Express-C 9 . All rights reserved. can use DB2 Express-C 9 to store any application data. On a development system where the test databases are small. 2006. It can handle increasing demand by scaling up (by adding more CPU and memory to one server) or scaling out (by adding more servers over an interconnection network). feel free to skip these sections. and operate it.4 compatible application server that can host applications constructed from Web components such as JavaServer Pages (JSP). Application Server has built-in support for J2EE Connector Architecture (JCA) 1. and scalable database server The core technology of DB2 has existed as an IBM product since 1983 and is a mature and robust database engine. Your production applications. It includes a fully licensed. The DB2 server is designed from the ground up to handle virtually unlimited developerWorks® Deploy applications on Application Server and DB2 Express-C 9 Once you have tested your application in Eclipse. you can have multiple instances running on one machine.

with even the largest member of the DB2 Universal Database family. 32-bit microprocessor-based server hardware (with extensions for 64-bit CPUs) and has built-in self-monitoring. A restriction with DB2 Express-C 9 is the memory size of the hardware on which you can run the server. All rights reserved. and tuning features that take most of the tedious work out of maintaining a database server. DB2 can grow with your needs. . If your needs grow past this range of capacity. The limit of 4GB of physical memory corresponds to the typical maximum addressable memory space for many 32-bit operating systems. fast development Page 6 of 60 © Copyright IBM Corporation 1994. Depending on your application and database design. There is practically no limit to the size of the databases that you can create and manage with DB2 Express-C 9. Integration with XML data DB2 Express-C 9 has built-in capabilities for handling and working with XML data. The hybrid relational and XML nature of DB2 Express-C 9 lets developers satisfy the XML data storage needs of modern Web services and systems based on service oriented architecture (SOA). DB2 Express-C 9 is the first version of DB2 Express-C that integrates native XML storage and XQuery capabilities. and triggers have been well-tested.without the need to perform any conversions -. built-in features of DB2 servers for over a single logical database instance. 2006. Should your data needs grow in the future. It is especially cost-effective for small enterprise installations because it eliminates the need to retain full-time database administration staff.developerWorks® ibm. Transactions. DB2 Express-C 9 can grow with your needs All the data content and schemas that you create using DB2 Express-C 9 are directly compatible -. referential constraints. Free software. XA distributed transactions. Built-in management and business application features DB2 Express-C 9 is optimized for running on widely available. XML documents are stored hierarchically into the columns of a table. chances are you need to look beyond 32-bit server hardware and operating systems anyway. maintenance. stored procedures. a 32-bit server equipped with 4GB of main memory can readily handle databases tens of gigabytes in size. scalable growth path without the need to tackle costly and often risky data conversion. The DB2 Universal Database family of products provides a smooth.

db2exc_91_WIN_x86. 2006. is in a compressed ZIP format. go to Download: DB2 Express-C 9. Page 7 of 60 .zip. For this tutorial. Downloading and installing DB2 Express-C 9 In this section. Registration is free and takes just minutes. you'll download and install DB2 Express-C 9 and build a sample shown in Figure 2. Before you proceed any further. make sure you are logged on to Windows as the same user who will create the application. Downloading DB2 Express-C 9 To download DB2 Express-C 9. The instructions in this tutorial cover the installation of DB2 Express-C 9 on 32-bit Windows-based systems only. Installing DB2 Express-C 9 Unzip the downloaded file. named db2exc_91_WIN_x86. If you do not yet have an IBM ID. is displayed: Figure The file you download. it uses the name of the logged-in Windows user. Then run SETUP. Setup Launchpad screen for DB2 Express-C 9 installer Free software. This eliminates the need to assign a specific level of privileges for your explorations. The DB2 Express-C 9 setup Launchpad developerWorks® Section 4. All rights reserved. fast development © Copyright IBM Corporation 1994. to a directory. you need to register before downloading DB2 Express-C 9.EXE to begin installing DB2 Express-C 9. Any tables that you build in the database are created under a schema with that username. In the case of Windows. you need to be aware that DB2 Express-C 9 uses the operating system's authentication system to authenticate users.

2006. All rights reserved. When prompted. This option takes up to 500MB of disk space. Then click Install Product. Figure 3. and read the release Read the installation prerequisites. Follow the wizard's directions to install DB2 Universal Database Express. Selecting typical installation for DB2 Express-C 9 Free software. verify that your hardware and software satisfy them. select the Typical installation type.developerWorks® ibm. . shown in Figure 3. fast development Page 8 of 60 © Copyright IBM Corporation 1994.

you should consult the DB2 Administration Server User Guide to determine the security scenario most applicable to your installation. Free software. accepting the defaults. The default is the Program Files\IBM\SQLLIB\ directory on the system drive. This tutorial refers to this directory as the SQLLIB directory. Windows user authentication assignments for DB2 installation In the Page 9 of 60 . All rights reserved. developerWorks® The next screen prompts you for an installation directory. This configures an instance called DB2 on your system and sets its default connection protocol to TCP/IP. select Use the same user name and password for the remaining DB2 services. fast development © Copyright IBM Corporation 1994. as shown in Figure 4: Figure 4. Completing the installation Follow the remaining steps in the installation wizard. To keep things simple for this development system. Installing the DB2 system services The next wizard screen sets up the user authorized for the DB2 Administration Server (DAS). when you install production server instance(s).

as shown in Figure 5: Figure 5. fast development Page 10 of 60 © Copyright IBM Corporation 1994. Understanding the DB2 Express-C 9 Free software. . To create this sample database. • A new menu named IBM DB2 with a variety of administrative and user tools (under the Windows Start menu). • The DB2 First Steps window appearing on your desktop. first click the Database Creation link on the left-hand side of the First Steps window. 2006. The wizard proceeds to create a database called SAMPLE. Then click the Create the SAMPLE Database button. All rights reserved. Section After the wizard completes the installation.developerWorks® ibm. you'll notice: • A new green DB2 tray icon (lower right-hand side of the screen next to the system clock). DB2 First Steps window Creating the sample database The application example that you'll work on later in this tutorial (see Creating a Web application with Eclipse and WTP) makes use of a sample database provided by the DB2 Express-C 9 installation.

Authentication server for clients. Page 11 of 60 . Handles remote commands for the DB2 instance. and developers DB2 system services DB2 Express-C 9 is a database server that can process many data-access and administration requests simultaneously. DB2 Governor DB2 JDBC Applet Server DB2 License Server db2govds db2jds db2licd DB2 Security Server db2sec DB2 Remote Command db2rcmd Executor Free software. DB2 Express system services on Windows installations Service name DB2 System Controller Executable name db2syscs Description The main controller that provides access to persistent data and manages storage allocation. users. memory-buffer pools. All rights reserved. The components can be grouped into two categories: • DB2 system services • DB2 tools and utilities for administrators. and so on. it can spawn additional processes to perform its developerWorks® components This section covers the DB2 Express-C 9 components you installed in the preceding section (Downloading and installing DB2 Express-C 9). Support for JDBC. Statistics collector for DB2 applications. On Windows systems. Monitors and enforces DB2 software license policies. Table 1 describes the system services that are installed on your system: Table 1. on Linux systems. fast development © Copyright IBM Corporation 1994. These requests can originate from the local machine and any number of client machines accessing the server. Requests are received through the network and processed on the server machine(s) by a set of collaborating system services. this controller spawns threads to perform work.

Executes fenced stored procedures and user-defined functions outside the engine's address space (for security implementations). . All rights reserved.developerWorks® ibm. the typical DB2 installation includes a rich set of tools. and developers Other than system services. Figure 6 provides an overview: Figure 6. DB2 tools for administrators. 2006. Not strictly a service. this provides a tray icon on the Windows desktop for quick access to DB2 utilities. Tools and developer support for DB2 Express-C 9 Free software. users. Manages registry for backward compatibility with earlier versions. db2fmp DB2 system tray manager db2systray If you examine the Windows Task Manager's task list (type Ctrl-Alt-Delete to invoke the Task Manager).com/developerWorks DB2 Database Administration Server DB2 Management Service DB2 Fence Mode Process db2dasrrm db2mgmtsvc Provides administration service functionality. fast development Page 12 of 60 © Copyright IBM Corporation 1994. you'll see several of these services running.

schemas. or modify objects and perform most administration tasks. Replication enables you to IDE tool that creates. Can view. GUI tools included with DB2 Express-C 9 installation Tool DB2 Control Center Access to tool • IBM DB2 > General Administration Tools > Control Center Right-click the tray icon and select DB2 Control Center db2cc from command line IBM DB2 > Information > Information Center db2ic from command line IBM DB2 > Development > Development Center db2dc from command line IBM DB2 > General Sets up replication environment for DB2 to DB2 replication. Python.NET developers can use the add-in support for development using the Microsoft Visual Studio . fast development © Copyright IBM Corporation 1994. • • DB2 Information Center • • DB2 Development Center • • DB2 Replication Center • Free software. tables. etc. and Ruby. Development support Java development support in DB2 Express-C 9 includes access through JDBC (a type 4 driver and a type 2 driver are available) and SQLJ static embedded SQL.NET development environment. Page 13 of 60 . GUI-based tools Table 2 briefly describes some of the GUI tools provided with DB2 Express-C 9. Windows . add. databases. 2006. Launches browser to a Web site containing comprehensive up-to-date documentation and information on the DB2 server. Also launches other GUI-based developerWorks® In Figure 6. Open source developers can take advantage of the support for development using popular scripting environments. All rights reserved. You can explore these tools at your leisure: Table 2. builds. the tools for DB2 Express-C 9 can be generally classified as command-line based or GUI-based. and deploys stored procedures and user-defined functions. Description Examines instances. including Perl.

Working with the DB2 Command Line Processor Some system administrators prefer a command-line interface over a GUI tool for the purpose of server control. The DB2 Express-C 9 Command Line Processor If you are more comfortable with a command-line interface to relational database servers than with a GUI tool. All rights reserved. Many tedious custom administrative tasks can be automated by creating scripts that execute against a command-line interface. 2006. This section explores the command-line interface for DB2 Express-C 9. To start the CLP. Section 6. . assuming you have set up your environment PATH variable to include SQLLIB\BIN. Alternatively. you'll feel right at home with DB2 Express-C 9's Command Line Processor (CLP). The DB2 CLP lets you work with the DB2 database using an interactive command-line interface with a rich set of commands. select IBM DB2 > Command Line Tools > Command Line Processor from the Windows Start menu. • See the DB2 documentation for information on other GUI tools.developerWorks® ibm. you can use the following command: db2 Figure 7 shows the DB2 CLP's greeting screen: Free software. DB2 Task Center • Tool that schedules scripts (DB2 or OS) and notifies users of a task outcome. fast development Page 14 of 60 © Copyright IBM Corporation 1994. You can literally perform everything that you can do from the GUI tools by using the Administration Tools > Replication Center • db2rc from command line IBM DB2 > General Administration Tools > Task Center db2tc from command line maintain up-to-date copies of your important data.

All rights developerWorks® Figure 7. 2006. Page 15 of 60 . fast development © Copyright IBM Corporation 1994. You are now connected to the SAMPLE database: Figure 8. Connecting to the SAMPLE database through the DB2 Express-C 9 CLP Free software. type the following command: connect to sample Figure 8 shows the result of this command. To connect to the SAMPLE database. Logging on to the CLP of DB2 Express-C 9 Data query with DB2 CLP The interactive CLP takes SQL commands as well as DB2-specific control

All rights reserved. 2006. who has the employee number of 000300. Free The SAMPLE database contains a table of employee information called EMPLOYEE.developerWorks® ibm. Try the following: select * from employee where empno='000300' The result is shown in the top half of Figure 9: Figure 9. You'll use this table throughout the remainder of this tutorial. the result is the record for Philip Smith. Command-line SQL queries in an interactive CLP session In Figure 9. . You can directly enter SQL queries against the table. fast development Page 16 of 60 © Copyright IBM Corporation 1994.


Figure 9 also illustrates the query to find all the employees with an annual salary of $90,000 or more:
select firstnme, lastname, salary from employee where salary > 90000

See Figure 9 for the result, showing four employees with salaries greater than $90,000. In addition to the standard SQL commands, many DB2-specific commands are available. You can use the ? command at any time to get help. To see the structure of the EMPLOYEE table, enter the following:
describe table employee

This command shows the fields structure of the EMPLOYEE table, as shown in Figure 10: Figure 10. Using the DESCRIBE command to display table schema

The application you'll work through later in this tutorial makes use of the EMPLOYEE

Free software, fast development © Copyright IBM Corporation 1994, 2006. All rights reserved.

Page 17 of 60



Creating your own data tables through the DB2 CLP
The DB2 CLP can take a text-based script file as input and execute each line of the script as if it were entered at the command line. The products.sql script file, found in the sql subdirectory of the code download for this article (see Download), is shown in Listing 1: Listing 1. The products.sql DB2 CLP script file for creating a table

This standard SQL script file connects to the SAMPLE database, creates a table called PRODUCTS, and places three rows in the table. The DB2 CLP can process this script. Just enter the following command:
db2 -vf products.sql -t

Figure 11 shows the result of this command: Figure 11. Processing a DB2 command script file using the CLP

Free software, fast development Page 18 of 60

© Copyright IBM Corporation 1994, 2006. All rights reserved.


You can get more information on the options available with the CLP from the Information Center. You can also explore the newly created database visually with the Control Center. The next section examines another important engine for your Web applications: WebSphere Application Server Community Edition.

Section 7. Introducing WebSphere Application Server Community Edition
WebSphere Application Server Community Edition (Application Server) is a J2EE 1.4 compatible application server and a member of the IBM WebSphere family of products. This section introduces you to Application Server's structure and functionality. If you prefer to use a different application server for the purposes of this tutorial, feel free to skip to Introducing the open source Eclipse IDE.

Server for J2EE 1.4 applications and Web services
Application Server is a no-license-cost server that supports the production hosting of Web applications and Web services created to the J2EE 1.4 standard. This includes applications that can contain the following elements:

Free software, fast development © Copyright IBM Corporation 1994, 2006. All rights reserved.

Page 19 of 60

For high-performance service of static Web assets. Since then. Tomcat has taken over as the de facto open source standard in Web-tier containers. . The first version of such a container was named JServ. Application Server has built-in support to interoperate with legacy CORBA systems.5 resource adapters connecting to EIS or legacy systems • Other data-access components Once a Geronimo The Application Server code is based on the popular Apache Geronimo project (see Resources). Application Server will continue to support tight integration with best-of-breed open source • JSPs • Servlets • Custom Java coding • EJBs • Model-view-controller (MVC) frameworks • Lightweight development frameworks • JCA 1. You can also use it to deploy and host Web services through its integration with Apache Axis (see Resources). you can configure the Apache JServ Protocol version 1.developerWorks® ibm. Application Server's open source pedigree Figure 12 shows the composition of Application Server.3 (AJP13) protocol connector to enable Application Server to accept requests from an industry-standard Apache Web server (front end) (see The AJP protocol). As such. And you can use Application Server as a general-purpose Web server to support the serving of static HTML pages and graphical images. 2006. Moving forward. Application Server's open source server components Free software. The AJP protocol This protocol is designed to enable the forwarding of requests for dynamic server contents (JSP and servlet) from an Apache Web server to an instance of a container for Java Servlets or JSPs. however. All rights reserved. You'll recognize many open source server components: Figure 12. it comes with the capability to integrate with a large body of open source technology. such as the Apache Tomcat Web container and the ActiveMQ message broker. fast development Page 20 of 60 © Copyright IBM Corporation 1994.

Initially. All rights reserved. (See Resources for OpenEJB's open source community Web developerWorks® Table 3 summarizes the open source server components shown in Figure 12: Table 3.1 API. Tomcat served as the reference container implementation for the latest JSP and Servlets specifications.) Popular message broker that supports a rich set of transports. 2006. Application Server integrates Tomcat 5. and 5.1 specification. Page 21 of 60 . Includes a JCA 1. (See Resources for Tomcat's open source community Web site. The open source server components inside Application Server Server Apache Tomcat Description Popular container for Web-tier components.) Based originally on code from IBM's Cloudscape ActiveMQ OpenEJB Apache Derby Free software. 4. Three version families of Tomcat are supported: resource adapter and support for Message Driven Beans. fast development © Copyright IBM Corporation 1994. Web-tier containers. including Container Managed Persistence (CMP) 2 and EJB Query Language (EJBQL). Overwhelming support from the developer and user communities has made it the de facto standard in open source.5. Supports the Java Message Service (JMS) 1.x.x. (See Resources for ActiveMQ's open source community Web site.) An EJB container supporting the EJB 2.x.

Optional additional downloads In addition to the Application Server and WTP server adapter downloads. go to Download: WebSphere Application Server Community Edition V1. All rights reserved.1.developerWorks® ibm.) Section 8. The corresponding Eclipse WTP server adapter for Application Server (formerly called the Application Server plug-in for Eclipse) can be downloaded and installed using the Eclipse update manager.0. you might also want to download these items from the same site: • Application Server bundled with IBM JRE version 1. The Application Server distribution you download is in Windows EXE format. 2006. fast development Page 22 of 60 © Copyright IBM Corporation 1994. (See Resources for Apache Derby's open source community Web site. optionally.0. but they can be helpful for your configuration.1.0 • Application Server sample applications These downloads are not mandatory. Apache Derby is a full-featured RDBMS created completely in Java code. Be sure to use version 1. This version is significantly different from version product. Downloading Application Server To download Application Server 1.1. Important note: The instructions in this tutorial pertain to version 1. Application Server currently uses Apache Derby as its own internal embedded database.5. You'll perform those steps later in this tutorial (see Downloading and installing Eclipse).1.1. .0.0.1 of Application Server.1 or later as you follow along with this tutorial. some additional items that might enhance your configuration) and performing the installation.0. Downloading and installing Application Server This section walks you through downloading Application Server (and. Installing Application Server Free software.

com/developerWorks developerWorks® To install Application Server. select IBM WebSphere > Application Server Community Edition > Start the server from the Windows Start menu. You should see a command console open that displays the server startup information. To start the server after installation. fast development © Copyright IBM Corporation Page 23 of 60 . run the downloaded EXE file on your system. 2006. similar to Figure 13: Figure 13. You can specify your own directory or accept the default. The installation wizard prompts you for a directory for the installation. Free software. start the Administration Console by selecting IBM WebSphere > Application Server Community Edition > Administration Console from the Windows Start menu. A system console showing output from the Application Server startup To verify the success of the installation. All rights reserved.

All rights reserved.developerWorks® ibm. use the predefined username Free software. If you wish to explore the Administration This should start an instance of your browser. Figure 14 shows the login screen for the console: Figure 14. pointed to the login page for the Administration Console. you can always reach the Administration Console on a browser with the URL http://localhost:8080/console/. The Administration Console is actually a Web application running inside Application Server. The login screen for the Application Server Administration Console Instead of using the menu selection. 2006. . fast development Page 24 of 60 © Copyright IBM Corporation 1994.

Page 25 of 60 . Applications that are deployed to Application Server are maintained by the server as configurations. select IBM WebSphere > Application Server Community Edition > Start the server from the Windows Start menu. All rights reserved. • Change directory to the bin directory just below Application Server installation directory (or add the bin directory to your PATH environment variable) and issue this command: shutdown Obtain a list of installed applications On Application Server. select IBM WebSphere > Application Server Community Edition > Stop the server. log on to the Administration Console (using system for username and manager for password) and Free software. installing applications to the server is called deployment. You can also change to the bin directory just below the Application Server installation directory (or add the bin directory to your PATH environment variable) and this command: startup Stopping the server To stop the server. • From the Windows Start menu. Operating your Application Server As with DB2 Express-C 9. fast development © Copyright IBM Corporation 1994. Section 2006. choose one of these three methods: • Log in to the Administration Console and select Shutdown from its menu on the left-hand side. To view the configurations deployed on the server. you can control the basic operations of your Application Server through either the Administration Console GUI or a command-line developerWorks® system) and password (manager). Starting the server To start the server. This section describes the basic commands available through either user interface.

fast development Page 26 of 60 © Copyright IBM Corporation 1994. Showing all configurations installed in a Application Server In Figure 15.developerWorks® ibm. 2006. Figure 15 shows the output from a list-modules command: Figure 15. EJB JARs. Web App WARs. or Application Clients. Free software. All rights reserved. You can also issue this command from a command line while you're in the bin subdirectory: deploy list-modules Application Server prompts you for a username and password (use system and manager). a configuration name preceded by a plus sign (+) indicates that it is installed and running. This runs the command-line deployer tool and obtains module information on all the configurations installed on this server. .com/developerWorks select Application EARs. A configuration name without the + indicates that it is installed but not currently running.

The action that you need to perform boils down to the following: 1. 2006. All rights reserved. Figure 16 shows the list of entries in the repository. Figure for the JDBC library JAR file and another for the license JAR file.5 resource adapter on Application Server that accesses your DB2 SAMPLE database. located in the code repository. This lets any application that's hosted in Application Server access the SAMPLE database containing the EMPLOYEE and PRODUCTS tables that you created earlier in the tutorial (see Working with the DB2 Command Line Processor).com/developerWorks developerWorks® Section 10. A resource adapter already exists in Application Server (from an open source implementation called TranQL) that works with the JDBC driver. The DB2 JDBC driver is now distributed as a standard part of Application Server. You need to look for two entries -. Click Common Libraries in the left-hand menu. This shows all the entries in the code repository where Application Server keeps binaries of system and application components. This resource adapter instance uses the DB2 Express-C 9 type 4 JDBC driver to access the SAMPLE database. Locating the DB2 Express-C 9 JDBC driver in the code repository of Application Server Creating a deployment plan to deploy the TranQL resource adapter. you need to create and deploy an instance of a JCA 1. Locating the DB2 JDBC driver and license JARs in Application Server repository Free software. you'll connect Application Server to DB2 Express-C 9. log on to the Application Server Administration Console. 2. Connecting Application Server to DB2 Express-C 9 In this section. Deploying a resource adapter To connect the Application Server with DB2 Express-C 9. configured with the JDBC driver Locating the DB2 Express JDBC driver in the Application Server repository First. Page 27 of 60 . fast development © Copyright IBM Corporation 1994.

you will find the JDBC library JAR and license JAR files in the following modules: • com.1/jar Now that you have confirmed their location and the associated module names.1/jar • com. To deploy the adapter.db2/db2jcc_license_cu/ fast development Page 28 of 60 © Copyright IBM Corporation 1994. From the list of common libraries in the repository. log on to the console and click Database Pools in the menu on the left-hand side. you can go ahead and use them to create a database pool. as shown in Figure 17: Free software.1 JDBC drivers set. The latest version of DB2 Express-C 9 requires the 9.developerWorks® ibm.5 resource adapter provides database pooling for all Application Server-hosted applications. You should see the currently deployed database pools. Adding a system-wide database pool The TranQL JCA 1. All rights .db2/db2jcc/9.

com/developerWorks developerWorks® Figure 17. the server-wide database pool called SystemDatasource accesses a Derby database that is used internally by Application Table 4.DB2Driver CTRL-click or SHIFT-click to select both: com. Page 29 of 60 .ibm.jcc. This will involve the next few screens of the wizard.db2/db2jcc_license_cu/ Displaying the currently configured database pools in Application Server In Figure fast development © Copyright IBM Corporation 1994.1/jar Windows user name under which DB2 Express-C 9 is installed DB User Name Free software. All rights reserved. Configuration for the Application Server database pool connecting to SAMPLE DB2 database Field Name of Database Pool Database Type JDBC Driver Class Driver JAR Value dwDatasource DB2 com. Fill in the details of the pool with values shown in Table 4.db2/db2jcc/9. 2006.1/jar com. Click the Create a new database pool: Using the Geronimo database pool wizard option.

Successful test connect to the DB2 Express-C 9 database from Application Server Viewing and deploying the plan The connection to DB2 Express-C 9 is now DB Password Port Database Host Windows user's password for DB2 Express-C 9 50000 sample localhost Leave the rest of the configuration empty. Follow these steps to view and then deploy the plan: 1.developerWorks® ibm. If the attempt is successful. fast development Page 30 of 60 © Copyright IBM Corporation 1994. and then click the Test Connection button. based on your input. . you must create and deploy a deployment plan. 2006. shown in Listing 2. This will display the generated deployment plan. you should see a screen similar to Figure 18: Figure 18. accepting the default values. This deployment plan can be generated for you automatically. Free software. This causes Application Server to attempt to connect to the SAMPLE database. All rights reserved. Click the Show Plan button (see Figure 18). but to access the data successfully from Application Server. by the wizard.

sql. The generated Application Server system-wide database pool deployment plan for the DB2 Express-C 9 database connection <?xml version="</dep:groupId> <dep:artifactId>db2jcc</dep:artifactId> <dep:version>9.db2. fast development © Copyright IBM Corporation Applications hosted in Application Server can now access the SAMPLE database by looking up the dwDatasource connection pool. the display should now show the dwDatasource pool as a deployed system-wide database pool.0</dep:version> <dep:type>rar</dep:type> </dep:moduleId> <dep:dependencies> <dep:dependency> <dep:groupId></dep:groupId> <dep:artifactId>db2jcc_license_cu</dep:artifactId> <dep:version>9.apache.1"> <dep:moduleId> <dep:groupId>console.0" encoding="UTF-8"?> <connector xmlns="http://geronimo.1"> <dep:environment xmlns:dep="http://geronimo. Page 31 of 60 .DB2Driver</config-property-setting> <config-property-setting name="UserName">sing</config-property-setting> <config-property-setting name="ConnectionURL"> jdbc:db2://localhost:50000/sample</config-property-setting> <connectionmanager> <local-transaction/> <single-pool> <max-size>10</max-size> <min-size>0</min-size> <match-one/> </single-pool> </connectionmanager> </connectiondefinition-instance> </connection-definition> </outbound-resourceadapter> </resourceadapter> </connector> If you select Database Pools again on the Web console menu. Listing 2. Free software.DataSource</connectionfactory-interface> <connectiondefinition-instance> <name>dwDatasource</name> <config-property-setting name="Password">mypassword</config-property-setting> <config-property-setting name="Driver"></dep:groupId> <dep:artifactId>dwDatasource</dep:artifactId> <dep:version> developerWorks®</dep:version> <dep:type>jar</dep:type> </dep:dependency> <dep:dependency> <dep:groupId> Click the Deploy button to deploy the plan. 2006.1</dep:version> <dep:type>jar</dep:type> </dep:dependency> </dep:dependencies> </dep:environment> <resourceadapter> <outbound-resourceadapter> <connection-definition> <connectionfactory-interface>javax. All rights reserved.

Eclipse has features that are very attractive to developers in general and Java developers in particular. as well as J2EE targets. Eclipse is supported by a huge global community of users. manage. Free software. such as Apache Ant • Tight integration with popular Java unit-testing frameworks. You'll likely discover even more useful features as you start coding with this workhorse IDE.) This section gives you an introduction to Eclipse. such as Subversion and CVS • Tight integration with popular Java build tools. such as JUnit • Ability to control. and test code bases that consist of up to millions of lines. debug. (See Resources for a link to the Eclipse community Web site. complex. including dynamic API documentation lookup • Support for the development of standard Java applications. XML. including: • Built-in smart editors for Java Section 11. All rights reserved. and error-prone refactoring process This is just a partial list of the features of Eclipse. fast development Page 32 of 60 © Copyright IBM Corporation 1994. Introducing the open source Eclipse IDE The open source Eclipse IDE is one of the most popular IDEs for Java development in the world.developerWorks® ibm. and so on • Full syntax highlighting on all editors • Full syntax check as you enter your code • Context-sensitive code assists for supported programming languages. 2006. Open source users and developers community Eclipse is used daily by Java development teams across the world to code. . and researchers. and deploy applications to servers during the test and debug cycle • Tight integration with relational database sources through JDBC • One-click ability to find the declaration of a type or base type anywhere in the source code • One-click ability to look up all references to a type or symbol anywhere in the source code • Refactoring tools that assist in the often tedious. developers. HTML. such as Web applications and Web services • Tight integration with popular version-control systems.

Features of the Eclipse IDE user interface made available to all plug-ins Uniform developer experience across platforms Eclipse's all-Java construction lets exactly the same IDE code and IDE user interface run on any supported OS and hardware platform. Mac OS X. and many open source and commercial products have leveraged Eclipse's open source code base. and others. Downloading and installing Eclipse Free software. and Ruby on Rails. fast development © Copyright IBM Corporation developerWorks® Reusable GUI framework Eclipse's modular architecture encourages customization and code reuse. such as C/C++. you will be right at home on any development platform. Eclipse has a well-specified plug-in API and rich support for plug-in construction. Eclipse plug-ins provide support for other popular development languages. Python. Figure 19 illustrates the rich features and versatile composition of the Eclipse IDE: Figure 19. including UNIX. The DB2 Express-C 9 Development Center is an example of a commercial product leveraging the Eclipse framework. Page 33 of 60 . The Eclipse IDE's GUI is designed to be reusable. All rights reserved. 2006. Linux. Section 12. Plug-ins extend Eclipse beyond Java programming In addition to the GUI Windows. third-party plug-ins that extend well beyond the realm of Java development. Once you become familiar with the UI and operations of Eclipse. This has created a foundation for an abundance of high-quality.

The release version that this tutorial is tested on is based on WTP 1. which starts Eclipse. You might want to drag-and-drop a shortcut onto your desktop or the system tray to make future launching of the IDE simpler. Make sure you download only the compatible binaries.exe file's structure as you unzip the distribution.exe or run it on the command line. All rights file's contents to a directory where you want Eclipse to be installed. 2006.2 and Eclipse WTP 1. Unzip and install the Eclipse WTP all-in-one distribution Installing Eclipse is as simple as unzipping the . Selecting the initial workspace for the Eclipse IDE Free In this section. After the splash screen. If you look into your distribution directory. and the download is wtp-all-in-one-sdk-R-1.developerWorks® ibm. Instead of downloading and installing Eclipse. Double-click eclipse. . Make sure you maintain the .5.5. The IDE should start. shown in Figure 20: Figure 20. you will find an eclipse. then all the dependencies separately. The Eclipse WTP server adapter for Application Server that you'll use for this tutorial has been tested on Eclipse 3. it prompts you to select a workspace. Downloading Eclipse You can download releases of the Eclipse IDE for your platform from the Eclipse Project Downloads page. fast development Page 34 of 60 © Copyright IBM Corporation 1994.5. you'll download and install the Eclipse IDE and the Eclipse WTP server adapter for Application Server. the WTP team provides an all-in-one binary download that can save you a lot of time and headaches. then WTP.1-200609230508-win32. Follow the links for the latest release at the Web Tools Platform downloads page to download a compatible version of the all-in-one binaries.

In the Install/Update wizard. To install the Eclipse WTP server adapter for Application Server: You can maintain as many projects as you wish in a workspace.1. Close Eclipse to prepare for the next developerWorks® A workspace is simply a directory where Eclipse manages source code and other artifacts of your projects. The best way to install the Eclipse WTP server adapter for Application Server is to use the Eclipse update manager. 3. The IDE starts up with a help screen that you can walk through the fundamentals of working with Eclipse. Using the update manager significantly simplifies the download and installation process. and enter the Name of Eclipse WTP server adapter for WAS CE 1. fast development © Copyright IBM Corporation 1994. Page 35 of 60 . All rights reserved. and set the Url to Free software. You can use multiple workspaces to work on the different branches. development staff often needs to work on multiple branches of the same source tree at the same time. 2. You can automate the testing/debug process using this server adapter because it can also install and uninstall applications directly to the connected instance of the Application Server. accept the default to let Eclipse create a new workspace for you. 2006. Eclipse WTP server adapter for Application Server installation The Eclipse WTP server adapter for Application Server lets you control an instance of Application Server within Eclipse. select Search for new features to install and click Next. if you wish. Click the New Remote Site button on the top right.. In production projects that use version control. For the purpose of this tutorial.. from the Eclipse menu. Select Help > Software Updates > Find and Install .

2006. as shown in Figure 21: Figure 21. From the Eclipse IDE menus. fast development Page 36 of 60 © Copyright IBM Corporation 1994. After installation. Section 13. Creating a DB2 Express-C 9 connection in the Database Explorer Start Eclipse in the workspace you created during the installation.boulder. 4. In the window.. select the Database Explorer Hands-on Eclipse: Connecting Eclipse to DB2 Express-C 9 This section shows how to use Eclipse's powerful Database Explorer view to connect to the DB2 Express SAMPLE database you created earlier in this http://download. the download manager might suggest a restart of the Eclipse environment. and the adapter will be installed and ready to go. Let the update manager restart the environment. select Window > Show View >® ibm.. All rights reserved. . Creating an Eclipse Database Explorer view Free software. Click Finish and let the update manager download and install the adapter.

ibm. Right-click the Connections element and select New Connection. pointing to your SAMPLE database: Figure 22. Connecting Eclipse to DB2 Express-C 9 through the JDBC driver Free software. developerWorks® A new Database Explorer view appears.. All rights reserved. Page 37 of 60 . fast development © Copyright IBM Corporation 1994... Fill in the connection information as shown in Figure 22.

the entire entry becomes: C:\Program Files\IBM\SQLLIB\java\db2jcc. In my setup.jar file. Click Browse to locate the SQLLIB/java subdirectory and select the db2jcc. . You must manually edit the entry to add the db2cc_license_cu. note that you need to enter the user ID and password of the Windows user under which you set up DB2 Express-C 9.jar The two entries are separated by a semicolon (. it should be your own Windows user ID and password.jar. 2006. C:\Program Files\IBM\SQLLIB\java\db2jcc_license_cu.developerWorks® ibm.jar JDBC driver. As you know from Downloading and installing DB2 Express-C 9.). Another important area is the Class location field (see Figure 22). In Figure 22. for example. fast development Page 38 of 60 © Copyright IBM Corporation 1994. the connection will be denied. If you have installed DB2 Free software. All rights reserved.

com/developerWorks developerWorks® Express-C 9 somewhere other than the default location. You should now be able to click Test Connection. Expand the SAMPLE connection to see your EMPLOYEE and PRODUCTS tables. A new SAMPLE connection appears in the Database Explorer view. you need to change the path accordingly. Finally. Page 39 of 60 . All rights reserved. Figure 23 shows the expanded EMPLOYEE table: Figure 23. click Finish. Exploring the SAMPLE DB2 Express-C 9 database from Eclipse Free software. fast development © Copyright IBM Corporation 1994. and Eclipse should report that the connection is successful.

com/developerWorks You can see how easy it is to access information on DB2 Express-C 9 databases from Eclipse. All rights reserved.developerWorks® ibm. fast development Page 40 of 60 © Copyright IBM Corporation 1994. . Free software. 2006.

as well as add rows to a table. Right-click the EMPLOYEE table and select Data > Edit. for example). You can see all the data in the table. field type. Examining table schema In Figure 23. as shown in Figure 24: Figure 24.right on the tree view display of the EMPLOYEE table. fast development © Copyright IBM Corporation 1994. You Free software. Eclipse Data Output view displaying DB2 Express-C 9 table contents To see the SQL statement that is executed on the DB2 engine. Eclipse opens up a database edit view. directly from the Database Explorer view. you can click the Messages tab of the Data Output view. Page 41 of 60 . Viewing the table content To see the contents of a table ( right-click the table and select Data > Sample Content. Modifying table content You can change the value of any developerWorks® Section 14. default values. you'll see some of the powerful features provided by the Database Explorer and Data Output views in Eclipse. Working with data in the Data Output and Database Explorer views Now that the connection to your DB2 database is established. you saw that the Database Explorer provides full field definition. All rights reserved. 2006. and primary key information -. This performs a SELECT * on the table and displays the result in a Data Output view.

and you can add new rows to the end of the table. DDL generated by Eclipse's Database Explorer for the EMPLOYEE table ALTER TABLE "SING". fast development Page 42 of 60 © Copyright IBM Corporation 1994. All rights reserved. Modifying DB2 Express-C 9 data from Eclipse Generating Data Definition Language (DDL) for your table Another useful feature available in Database Explorer view is the ability to generate Data Definition Language (DDL) scripts from your connected databases. This brings up a wizard that guides you through the DDL generation process.. The wizard's final screen previews the generated DDL. right-click EMPLOYEE and select Data > Generate can change the data in the fields. Figure 25 shows this editable view: Figure 25. .. 2006. For the EMPLOYEE table.. it is similar to Listing 3: Listing 3.developerWorks® ibm. .. To see this in action. Select all the check boxes in the wizard's first two screens. Free software.."EMPLOYEE" DROP CONSTRAINT "RED".

"PHONENO" CHAR(4). "HIREDATE" DATE. All rights reserved. "WORKDEPT" CHAR(3). "BIRTHDATE" DATE. fast development © Copyright IBM Corporation 1994. The connections and relationships among Eclipse. Relationships among Eclipse."EMPLOYEE" ( "EMPNO" CHAR(6) NOT NULL. Kick-start components working together Now you'll put together what you've learned so far in this tutorial and develop a data-driven Web application in the Eclipse IDE. to Application Server and test it there. illustrated in Figure 26. Application Server. are key to this scenario: Figure 26. You can use this DDL to re-create the table on any DB2 database. . bundled in a standard Web application archive (WAR) file. "LASTNAME" VARCHAR(15) NOT NULL. "BONUS" DECIMAL(10 . 2). "SALARY" DECIMAL(10 . and DB2 Express-C 9. "JOB" CHAR(8). Application Server. you'll create a simple Web application consisting of a single JSP that accesses data in your SAMPLE database and an associated stylesheet. This application accesses the DB2 Express-C 9 server through the database pool that you set up earlier in this tutorial (see Connecting Application Server to DB2 Express-C 9). Creating a Web application with Eclipse and WTP In this section. 2006. "MIDINIT" CHAR(1) developerWorks® CREATE TABLE "SING". "COMM" DECIMAL(10 . 2). Page 43 of 60 . "SEX" CHAR(1).ibm. You can save this DDL to a file or execute it on a server (perhaps creating the same table in another database). "EDLEVEL" SMALLINT NOT NULL. Section 15. and DB2 Express-C 9 Free software.. You'll deploy the Web application. 2) ). "FIRSTNME" VARCHAR(12) NOT NULL.

• Accept the default for everything else. 2006. 4. Eclipse's Database Explorer and Data Output views are used to access directly the database schema and content managed in DB2 Express-C 9. In the wizard screens: • Enter dwapp for the Project name. Application Server is configured with a JDBC data pool that accesses DB2 Express-C 9 databases. Figure 27 shows the directory structure of the dwapp project you've created using Eclipse's Navigator view: Figure 27. 3. Creating a new Eclipse project Follow these steps to create a new Web project for Application Server deployment: 1. .developerWorks® ibm. • Select Apache Geronimo v 1. Start Eclipse and select File > New > Project.. select Web > Dynamic Web In Figure 26. from the application menu.0 for the Target runtime. Creating a new dynamic Web project on the Eclipse IDE Free software. fast development Page 44 of 60 © Copyright IBM Corporation 1994. Shut down your Application Server server.. All rights reserved. From the window. 2.

The wizard has also generated two XML files automatically. Wizard-generated XML files for developerWorks® Generated deployment descriptor and plan Web applications are archived into standard WAR file format before they can be deployed to a compatible server.4 standard specifications.xml Description Standard J2EE deployment descriptor for Web applications running on compatible containers. Page 45 of 60 .xml Coding a JSP to access EMPLOYEE data Free software. All rights reserved. described in Table 5: Table 5. you can see the standard J2EE WAR file layout of directories. WEB-INF/geronimo-web. Must be included with every deployed WAR file. This plan describes server customization for deployment of this application. under the WebContent directory.4 J2EE dynamic Web applications Generated XML file WEB-INF/web. The organization of these WAR files is governed by the J2EE Application Server specific deployment plan. fast development © Copyright IBM Corporation 1994. 2006. In Figure 27.

With the WebContent directory highlighted. charset=ISO-8859-1"> <link rel="stylesheet" type="text/css" href="dwstyles.phoneno}"/></td> <td><c:out value="${employee. 3..firstnme}"/></td> <td><c:out value="${employee. charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="sql" uri="http://java.salary}"/></td> <td><c:out value="${employee. Name the page index. 2. Click Now you'll create a JSP that accesses the data in the EMPLOYEE table: 1. 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/" %> <%@ taglib prefix="c" uri="http://java. 2006.bonus}"/></td> <td><c:out value="${employee. Listing 4.job}"/></td> <td><c:out value="${employee. fast development Page 46 of 60 © Copyright IBM Corporation 1994.DB2 Express Employee List</h1> <br> <table> <tr> <th>Emp no</th> <th>First name</th> <th>Last name</th> <th>Phone</th> <th>Job</th> <th>Salary</th> <th>Bonus</th> <th>Commission</th> <th>Department</th> </tr> <sql:query var="employees" dataSource="jdbc/DataSource"> SELECT * FROM EMPLOYEE </sql:query> <c:forEach var="employee" items="${employees. From the wizard. .&nbsp. JSP accessing employee data from the DB2 Express-C 9 SAMPLE database <%@ page language="java" contentType="text/html.workdept}"/></td> </tr> </c:forEach> </table> </code> Free"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.sun.developerWorks® ibm. Eclipse generates a skeletal JSP page from a template.comm}"/></td> <td><c:out value="${employee. you can copy the source from this tutorial's code download (see Download). Alternatively.lastname}"/></td> <td><c:out value="${employee. All rights reserved.rows}"> <tr> <td><c:out value="${employee.css"/> <title>dW Example Employee Data from DB2 Express-C 9 Table</title> </head> <body> <h1>&nbsp.jsp.sun.. Edit the page to match Listing 4.empno}"/></td> <td><c:out value="${employee. select Web > JSP.. right-click and select New > Other.

org/2001/XMLSchema-instance" xsi:schemaLocation= "http://java.html</welcome-file> <welcome-file>index.jsp page.xsd"> <display-name> dwapp</display-name> <welcome-file-list> <welcome-file>index.4" xmlns="http://java.xml file.sql.DataSource</res-type> Free software.jsp</welcome-file> </welcome-file-list> <resource-ref> <res-ref-name>jdbc/DataSource</res-ref-name> <res-type>javax. The result of the query is assigned to the employees" xmlns:xsi="http://www.jsp</welcome-file> <welcome-file>default. Listing 5. The boldfaced lines in Listing 4 show how the <sql:query> tag accesses a JDBC data source called jdbc/DataSource to execute the SQL SELECT statement. This is standard J2EE flexibility. when deployed to Application Server. http://java.0" encoding="UTF-8"?> <web-app id="dwapp" version="2.) Make sure you save the updated web. J2EE deployment descriptor -. The deployable application WAR file contains references to resources (such as a data source) that is resolved only when the application is deployed. This enables the same code module to be deployed. needs to resolve the data source named jdbc/DataSource.html</welcome-file> <welcome-file>default. it does not contain any embedded Java code. on different application servers against different database servers. which points to the DB2 Express-C 9 SAMPLE Examine the web. Page 47 of 60 . Each row displayed represents one employee record maintained in the DB2 Express-C 9 EMPLOYEE developerWorks® </body> </html> This JSP prints out a table of employee information. 2006. Embedded Java code in JSP is often viewed as a bad practice because it tends to become error-prone and unmanageable in the long term. All rights reserved. without reassembly.htm</welcome-file> <welcome-file>index. fast development © Copyright IBM Corporation 1994.xml file that is generated and make sure you add the boldfaced lines from Listing 5.sun. you need to make sure that it resolves to the dwDatasource that you set up earlier.sun. Each row of this result is then displayed using a <c:forEach> iterative tag. The coding makes use of only JSP Standard Tag Library (JSTL) tags and Expression Language (EL).w3.sun.web. (You might need to click the Source tab of the Eclipse XML file editor.htm</welcome-file> <welcome-file>default. Linking an application data source reference to an Application Server database pool The index.xml for the application <?xml version="1.

org/xml/ns/deployment-1. (Click the Source tab of the deployment plan editor.1" xmlns:sec="http://geronimo.xml <?xml version="1.5 resource adapter instance that you configured earlier is available to this <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </web-app> The <resource-ref> provides information to the container (Tomcat in this case) on the external resource references that need to be resolved.® ibm. Note that <sys:version> and <sys:type> of the <sys:dependency> are not specified.) Add the boldfaced lines shown in Listing 6 to the deployment plan and save it: Listing 6.apache.dbpool</sys:groupId> <sys:artifactId>dwDatasource</sys:artifactId> </sys:dependency> </sys:dependencies> </sys:environment> <context-root>/dwapp</context-root> <resource-ref> <ref-name>jdbc/DataSource</ref-name> <resource-link>dwDatasource</resource-link> </resource-ref> </web-app> Adding a <sys:dependency> pointing to console.dbpool/dwDatasource ensures that the JCA 1.1" xmlns:sys="http://geronimo. Application Server will treat this as a wildcard and look up the resource matching any version or type.0</sys:version> <sys:type>car</sys:type> </sys:moduleId> <sys:dependencies> <sys:dependency> <sys:groupId>console.1"> <sys:environment> <sys:moduleId> <sys:groupId>default</sys:groupId> <sys:artifactId>dwapp</sys:artifactId> <sys:version>1. Downloading and copying JSTL library JARs You must explicitly include the support libraries for JSTL 1.apache.apache. you make the actual link to the dwDatasource. All rights reserved.1 when you use a J2EE Free software. The Application Server specific deployment plan -geronimo-web. In the geronimo-web.1" xmlns:nam="http://geronimo.xml deployment plan in Eclipse. fast development Page 48 of 60 © Copyright IBM Corporation 1994. . The <nam:resource-ref> element tells Tomcat in Application Server that the jdbc/DataSource reference should be linked to the configured dwDatasource database pool.apache.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.xml. Examine the geronimo-web.

align: left. Edit the dwstyles. color: green. For your convenience. Page 49 of 60 . adding the content in Listing 7.. font-weight: bold. fast development © Copyright IBM Corporation developerWorks® 1. font-size: 13. You can also copy-and-paste from the code distribution (see Download).jar You can download these JAR files from the Jakarta Taglibs page. they are also included in this tutorial's code distribution under the jstl subdirectory (see Download). } Free software. just place the static content starting from the WebContent directory in your Eclipse project.css -. 2006.jar • standard. font-size: 38. The library JAR files include: • jstl. All rights reserved. font-style: italic.css file. font-weight: bold. dwstyles. the reference implementations of these libraries are maintained as part of the Apache Jakarta Taglibs and accept the default template for the stylesheet.) Currently. Name the stylesheet dwstyles. (This support is due to become a standard part of Java EE 5. align: left.A static stylesheet for formatting the data output h1 { font-family: arial. select Web > CSS. Application Server as a Web server: Adding static content So far you've learned how to generate content dynamically by executing JSP code on Application Server. } th { font-family: verdana. If your Web project requires static content service. background-color: black. From the pop-up window. Listing 7. You'll add a static Cascading Style Sheet (CSS) to the application to enhance its appearance. arial. Right-click the WebContent directory and select New > Other.. color: white. But Application Server also has the built-in capability to act as a regular Web server that serves static content.4 application server. Copy both of these JAR files to the WebContent/WEB-INF/lib directory of your Eclipse project before proceeding.

Deploying applications to Application Server Alternative way to deploy applications The WTP server adapter for Application Server is currently undergoing active development in the open source community.jsp. If the first page of your Web project is static and not dynamically generated. align: left. To export a WAR file. Right-click the dwapp element in Eclipse's Navigator and select Run as > Run on Server. Your user's browser accesses this static stylesheet to format the dynamic output from index.html page to the WebContent directory. 2006. font-size: 12. border-width: thin. font-style: italic. Then. you can simply add an index. right-click on the dwapp project and select Export. the stylesheet is accessible directly.. Select Deploy New from the menu. In the Run On Server wizard that opens (shown in Figure 28) td { font-family: verdana. When you deploy the application. as static content.developerWorks® ibm. . Make sure you select the check box named Set server as project default (do not ask again). All rights reserved. You are now ready to deploy the dwapp application to Application Server.1 Server. } Save the modified stylesheet. from Application Server. Figure 28. select WebSphere Application Server Community Edition v1. Click Install to deploy and start the application. select Web > WAR file. A sure-fire way of deploying the application to Application Server is to export the project as a WAR file and then deploy it using the Application Server console. Click the Browse button and locate the WAR file.. Save the exported WAR file to a directory of your choice where it can be found easily. 4. with the Application Server running: 1. } table { border-style: solid. The Run On Server wizard connecting Eclipse to a Application Server instance Free software... Depending on the JVM version and operating system you are using. 2. In the Export Wizard.. arial. you might encounter some problems with the adapter. fast development Page 50 of 60 © Copyright IBM Corporation 1994. Log in to the console. 3.

ibm. Also enter the directory where you have installed Application Server. All rights reserved. Page 51 of 60 . Specifying JRE and Application Server runtime for the Eclipse connected server Free software. This is shown in Figure 29: Figure 29. 2006. fast development © Copyright IBM Corporation developerWorks® Click Next and select the JRE that you are using. (It must be one of the JRE releases listed in System requirements).

All rights reserved. Successful Eclipse deployment of an Application Server application accessing DB2 Express-C 9 data Free software.developerWorks® Click Finish and wait while Eclipse starts Application Server and deploys the application to Application Server. You should see the list of employees displayed on a Web browser window within the Eclipse IDE. . fast development Page 52 of 60 © Copyright IBM Corporation 1994. as shown in Figure 30: Figure 30. 2006.

this tutorial has focused the setup for Application Server on ease of application development and test deployment. 2006. you can configure the same Application Server for production. Configuring Application Server for an Internet Web site So far. Application Server as a Web server If your machine were set up as an Internet-accessible server. fast development © Copyright IBM Corporation 1994. At any time during your development developerWorks® The IDE is now connected to Application Server for rapid development and deployment. Your application users can then see your application changes immediately after you deploy the application to the server. All rights reserved. the users accessing Free software. Section 16. Page 53 of 60 . In this section. you'll configure Application Server as a general Web server on the If you wish. you can deploy your application to Application Server for testing.

2006. fast development Page 54 of 60 © Copyright IBM Corporation your application over the Internet would need to use the URL http://your www domain name:8080/your application name. This is shown in Figure 31: Figure 31. Port 80 is the default TCP port for the HTTP protocol. It involves two steps: 1. one for Secure Sockets Layer (SSL)-based connections. If you use port 80 on the Application Server.developerWorks® ibm. Now you'll learn how to configure Application Server to accept the URL http://your Web domain name/. one for regular Web connections. users do not need to specify explicitly the port when they access your site. and one for the AJP protocol. Log on to the Application Server Administration Console and select Web Server on the left-hand side menu. 2. . You'll see three connectors running. All rights reserved. Changing the TCP port that the Tomcat (Web connector) listener is listening to Changing the application context of the application deployed on Application Server Changing the Tomcat listener port You need to change the Application Server default port 8080 assignment to port 80. Changing the port of the TomcatWebConnector for Internet user access Free software.

apache.apache. shut down the server and restart it. fast development © Copyright IBM Corporation 1994.apache. to get rid of the need to type the name of the All rights reserved. The element you need to modify is named <context-root>. Modifying geronimo-web. Next. On the next screen. if you want to move the dwapp application to the root context.xml plan: Listing 8. Now.1" xmlns:nam="http://geronimo. replace port 8080 with port 80 and click Save. Page 55 of 60 .com/developerWorks developerWorks® Click the edit link next to the HTTP-based TomcatWebConnector.apache.xml to deploy application at server root <?xml version="1. 2006. you'll modify the application deployment context to map to the root or /.ibm. For" xmlns:sys="http://geronimo.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.1"> Free software. you need to make the change shown in boldface in Listing 8 to its geronimo-web. Your Application Server application is now accessible at http://your WWW domain name/your application name. Modifying the application deployment context To map the application deployment context root to /.org/xml/ns/deployment-1. you need to modify the" xmlns:sec="http://geronimo.xml deployment plan in your project.

using its rich set of GUI tools and command-line tools • Created database tables with DB2 Express-C 9 and queried against them using SQL commands • Installed and worked with WebSphere Application Server Community Edition. and deployment life simpler. development. . fast development Page 56 of 60 © Copyright IBM Corporation 1994. As a Java Web developer. using its Web-based Administration Console as well as the command-line deployer tool • Connected WebSphere Application Server Community Edition to DB2 Express-C 9 by deploying a system-wide database pool to the DB2 database • Installed the Eclipse IDE. and IBM WebSphere Application Server Community Edition are all your disposal. you now have a choice of many free-to-license servers and development tools that a few short years ago were available to only the largest enterprise development teams. and the Eclipse WTP server adapter for WebSphere Application Server Free <sys:environment> <sys:moduleId> <sys:groupId>default</sys:groupId> <sys:artifactId>dwapp</sys:artifactId> <sys:version>1. Summary You are at an historical moment in the evolution of the software industry. All rights reserved.0</sys:version> <sys:type>car</sys:type> </sys:moduleId> <sys:dependencies> <sys:dependency> <sys:groupId>console. 2006. the IBM DB2 Express-C 9 database. you have: • Installed and became familiar with DB2 Express-C 9.developerWorks® ibm. In this tutorial.dbpool</sys:groupId> <sys:artifactId>dwDatasource</sys:artifactId> </sys:dependency> </sys:dependencies> </sys:environment> <context-root>/</context-root> <resource-ref> <ref-name>jdbc/DataSource</ref-name> <resource-link>dwDatasource</resource-link> </resource-ref> </web-app> Section 17. testing. the supporting Web Tools Platform. only a short click away. This collection of servers and IDEs works very well together to make your design. The open source Eclipse IDE.

supported through the Eclipse WTP server adapter for WebSphere Application Server Community Edition • Successfully developed an application on Eclipse. modify data. fast development © Copyright IBM Corporation developerWorks® Community Edition • Connected Eclipse to DB2 Express-C 9 through Eclipse's versatile Database Explorer view. All rights reserved. 2006. and made the application use DB2 Express-C 9 as its data supplier • Configured WebSphere Application Server Community Edition for access by users over the Internet You are now well on your way to developing and deploying your own Web applications on this powerful collection of software server and see table data content. Free software. Page 57 of 60 . and generate DDL • Used Eclipse to create a Web application and deployed it to WebSphere Application Server Community Edition with one click. which lets you view schema structure. deployed it to WebSphere Application Server Community Edition.

developerWorks® ibm. fast development Page 58 of 60 © Copyright IBM Corporation 1994. 2006.zip725KB Free software. All rights reserved. .com/developerWorks Downloads Description Sample code for this tutorial Information about download methods Name Size Download method HTTP j-kickstartcode.

• Migrate to DB2 Express-C: Resources to help you get started migrating to DB2 Express-C today. • "Get started with WebSphere Application Server Community Edition" (Nell Gawor and Lin Sun. open source JMS 1. from setting up your environment and choosing the right download package to deploying applications. • Apache Axis: Apache's reliable and stable base for implementing Java Web services. • "Manage your Eclipse environment" (Chris Aniszczyk and Phil Crosby. developerWorks® Resources Learn • "DB2 Express-C. February 2006): Get started quickly using DB2 Express-C for all of your applications. • Apache Tomcat: The Apache servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. November 2005): An excellent guide for migrating your applications. and more developerWorks. Page 59 of 60 . developerWorks. developerWorks. and install your plug-ins. fast development © Copyright IBM Corporation 1994. • "Migrate from Apache Tomcat to WebSphere Application Server Community Edition" (Sing Li. the developer-friendly alternative" (Grant Hutchison. • Get started now with Eclipse: The developerWorks Eclipse resource page. • "Developing Eclipse plug-ins" (David Gallardo. • Apache Geronimo: The J2EE server from Apache. • "Migrate from JBoss to WebSphere Application Server Community Edition" (Shyam Nagarajan. 2006. • "Migrating to Eclipse": A developer's guide to evaluating Eclipse. November 2005): Author Sing Li demonstrates how to migrate a J2EE Web tier application from Apache Tomcat 5. articles.5 to WebSphere Application Server Community Edition V1.1 provider.0. February 2006): Zen and the art of Eclipse maintenance. • ActiveMQ: Try out this fast. • Apache Derby: Apache's relational database implemented entirely in Java. December 2002): Learn to create. debug. • WebSphere Application Server Community Edition: Documentation. • "WebSphere Application Server Community Edition system administration": Learn everything you need to know to successfully administer a WebSphere Application Server Community Edition environment. developerWorks. All rights reserved. which supports Free software. developerWorks. December 2005): Learn what you need to know to get up and running quickly with WebSphere Application Server Community Edition. FAQs.

lightweight containers. peer Discuss • DB2 Express forum • eclipse. He is an evangelist of the open source. Professional Jini. All rights reserved. configurable. and XA and integrates seamlessly into J2EE 1. • Open EJB: Learn more about this open source. Pro JSP . Free software.developerWorks® ibm. Get the all-in-one Eclipse binary download from the Web Tools Platform downloads page. and numerous other books. discovery.4 containers. . Early Adopter clustering. SSL. Third Edition . • DB2 Express-C: Download the database • Eclipse newsgroups • Eclipse developer mailing lists • developerWorks blogs About the author Sing Li Sing is a consultant and an active author with over two decades of industry experience. modular. 2006. Sing also writes for technical magazines and participates in open source communities. fast development Page 60 of 60 © Copyright IBM Corporation 1994. Get products and technologies • WebSphere Application Server Community Edition: Download the application server. TCP. Professional Apache Tomcat 5. multicast. • Eclipse: Download the Eclipse SDK. VOIP. He has contributed to Beginning JavaServer Pages. and any Java application. You can reach Sing at westmakaha@yahoo. and P2P movements. persistence. and extendable EJB Container System and EJB Server. Beginning J2ME: From Novice to Professional.Third Edition.

Sign up to vote on this title
UsefulNot useful