This topic tells you how to work with the Online Auction sample application
by completing one or both of the following activities:
The sample application features an auction Web site, where you can browse
auction items, submit items for sale, and bid on items. Running the application
gives you a quick feel for the kind of J2EE application that you can build
with IBM Rational Developer. Also, the ready-made sample application contains a number
of J2EE components that you can browse and reuse.
Building the application will give you a solid introduction to many of the
IBM Rational Developer tools, such as the EJB tools. To save time, some of the required
components for building the application are already provided, such as the GIF
images and some source code.
Even if you want to build the application, you may want to run the ready-made
sample application first. This will show you how the application works before
you actually build it, which will aid you in your development tasks.
Note: If you followed the instructions in Part 2 below and you built
the sample application before you followed these instructions on running
the ready-made application, then you will need to remove the Auction project
from the server configuration before you can run the ready-made application.
Instructions for removing the Auction project from the server configuration
are found in the final step of the Test the application section of Part 2.
To run the ready-made application:
- Click File > Import. The Import Wizard is displayed.
- Select WebLogic EAR file and click Next. The enterprise
application import wizard is displayed.
- In the EAR file textbox, specify the following EAR file (where install_path is the directory where you have installed IBM Rational Developer):
install_path\eclipse\plugins\com.ibm.etools.weblogic.scenario.auction.doc\Auction.ear
- In the Target server field, select your WebLogic Server
version. Click Finish.
- In the Project Explorer, right-click AuctionEJB and select Properties. In
the left pane, select Java Build Path, and then view the Libraries tab.
- Click Add External JARs and add the following files (where install_path is
the directory where you have installed IBM Rational Developer):
install_path\eclipse\plugins\com.ibm.etools.dbjars_6.0.0\jars\dbbeans.jar
install_path\runtimes\base_v6_stub\lib\ivjejb35.jar
- View the Order and Export tab and check ivjejb35.jar to export the JAR to dependent projects.
- Click OK to close the Properties dialog.
- In the Project Explorer, expand AuctionEJB and double-click the Deployment Descriptor to open
it in the EJB Deployment Descriptor Editor. View the WebLogic page.
- Select Onlineitem in the left column and ensure the following
are true:
JNDI Name: com/acme/ejb/OnlineitemHome
Local JNDI Name: com/acme/ejb/OnlineitemLocalHome
Data Source Name: jdbc/dreamauc
- Select ItemHelper in the left column and ensure the JNDI
Name is com/acme/ejb/ItemHelperHome.
- Save the Deployment Descriptor Editor by selecting File > Save.
- From the menu, go Project > Build All.
- Follow the instructions for running the sample application.
To build the sample application, you must perform the following tasks:
These tasks are described in the sections below.
In the workbench, everything must reside in a project. A project is the top
level of organization of your resources in the workbench. A project contains
files and folders. Projects are used for building, version management, sharing,
and organizing resources. A project can contain session and persistent properties,
settings for environmental variables, and references to other projects. As
resources are created and modified within a project or projects, builders are
run and constraints are maintained. Builders create or modify resources within
projects, usually based on the existence and state of other resources. For
example, a Java builder converts Java source files into executable class files,
a Web link builder updates links to files when names and locations have changed,
and so on.
In this section, you create an Enterprise Application project named Auction.
Enterprise Application projects contain the resources needed for enterprise
applications and can contain a combination of Web modules, JAR files, EJB modules,
and application client modules. An Enterprise Application project is deployed
in the form of an EAR file. You also create an EJB project named AuctionEJB
and a Web project named AuctionWeb, which are both referenced by the Auction
enterprise application project. EJB projects contain the metadata files (such
as the deployment descriptor, IBM(R) extensions, and RDB mappings)
for the EJB application, Java source files, compiled code for the enterprise
beans, and stubs for the beans. An EJB project is deployed as an EJB module
(JAR file). Web projects contain servlets, JSP files, Java files, static documents
(for example HTML pages or images), and any associated metadata. A Web project
is deployed as a Web module (WAR file). All three projects are created in a
single step using a wizard.
To create the three types of projects that are required for this application:
- Open IBM Rational Developer.
- Switch to the J2EE perspective (Window > Open Perspective > Other > J2EE).
- If you ran the ready-made sample application by following the instructions
in "Part 1 - Running the ready-made sample application", then you must remove
the Auction project from the server by completing the
following steps:
- In the Servers view, right-click the WebLogic server and select Add and remove projects.
- Remove Auction from the Configured projects list and click Finish.
- From the menu, go to File > New > Enterprise Application Project.
- In the Name field, type Auction.
- Click Show Advanced to show the advanced options.
- Set J2EE version to 1.3.
- Select a WebLogic server runtime in Target server. One should have been created in the Install IBM Rational Deployment Toolkit for WebLogic Server section of "Preparing for the Online Auction sample application".
- Click Next.
- Click the New Module button.
- Clear the Application Client project and Connector project check boxes.
- Accept the default names that appear in the EJB project and Web
project fields and click Finish to create the EAR modules.
- Click Finish to create the enterprise application project.
- In the Project Explorer view, expand Enterprise Applications, Dynamic Web Projects,
and EJB Projects to see the new projects. The enterprise application project
named Auction, the EJB project named AuctionEJB, and the Web project named
AuctionWeb are all added to the workbench.
- Right-click on the AuctionEJB project and select Properties from
the context menu.
- In the left pane, select Validation.
- Clear the Override validation preferences check box and then clear
the Run validation automatically when you save changes to AuctionEJB resources check
box.
- Click OK to save your changes.
In this section, you learn how to add the following enterprise beans to the
AuctionEJB project:
- A CMP entity bean named Onlineitem (using the bottom-up mapping approach).
Entity beans with container-managed persistence (CMP) fields must be mapped
to database tables that are represented in a schema. You map entity beans
to database tables by creating a map. Maps are used to generate the SQL and
other supporting code needed to make enterprise beans persistent. You will
use the bottom-up mapping approach to create the Onlineitem bean. This approach
assumes that the database tables already exist, and that once the selected
tables are imported, the enterprise beans and mappings between them are automatically
generated.
- An access bean named OnlineitemData (using the Create an Access Bean wizard).
An access bean is an enterprise bean wrapper that is typically used by client
programs, such as JSP files and servlets. Access beans simplify client access
to enterprise beans and improve the performance of reading and writing multiple
EJB properties.
- A session bean named ItemHelper (using the Create an Enterprise bean wizard).
Session beans are non-persistent enterprise beans that do not require database
access, though they can obtain it indirectly (as needed) by accessing entity
beans
To create a CMP entity bean in the EJB project:
- In the Project Explorer view, expand AuctionEJB.
- Right-click the Deployment Descriptor and select New > Enterprise
Bean. The enterprise bean creation wizard opens.
- Ensure that the EJB project field is set to AuctionEJB.
- Select the Entity bean with container-managed persistence (CMP) fields radio
button.
- Set the CMP version to 2.x.
- In the Bean name field, type Onlineitem.
- In the Default package field, type com.acme.ejb. Click Next.
- Select (check) the Remote client view checkbox.
- We now need to add the fields to the CMP bean:
- First, remove the default CMP field by selecting it in the CMP attributes
list box and clicking Remove.
- Now, click the Add button to display the Create CMP Attribute dialog box.
- In the Name field, type itemtypeid.
- In the Type field, type java.lang.Integer.
- Select (check) the Key field checkbox. This will be the only
key field in this bean. Click Apply.
- Enter the remaining field names and types shown in the table below.
Click Close when you have finished entering the fields.
Name |
Type |
catalognumber |
java.lang.Integer |
title |
java.lang.String |
description |
java.lang.String |
value |
java.lang.Long |
startingbid |
java.lang.Long |
imagelocn |
java.lang.String |
imagelocnsm |
java.lang.String |
lastbid |
java.lang.Long |
lastbidder |
java.lang.String |
- Clear the Use the single key attribute type for the key class checkbox.
Ensure that the Key class field contains the class com.acme.ejb.OnlineitemKey.
- Click Finish.
To map the CMP enity bean fields to the database:
- In the Project Explorer view, right-click AuctionEJB and select EJB to RDB Mapping > Generate Map.
- Select Create a new backend folder and click Next.
- Select Top-Down and click Next.
- Set the Target database to DB2 Universal Database V8.1.
- Enter SAMPLE as the Database name and ensure Generate DDL is checked.
- Click Finish. The Mapping Editor will open.
- The column mappings for each field should be set up up correctly already.
Confirm this by clicking on each field in the Overview section,
ensuring that the field and database column names match, as follows:
Field Name |
DBMS Column |
itemtypeid |
ITEMTYPEID |
catalognumber |
CATALOGNUMBER |
title |
TITLE |
description |
DESCRIPTION |
value |
VALUE |
startingbid |
STARTINGBID |
imagelocn |
IMAGELOCN |
imagelocnsm |
IMAGELOCNSM |
lastbid |
LASTBID |
lastbidder |
LASTBIDDER |
- Save and close the Mapping Editor.
To create a database schema and tables:
- In the Project Explorer view, the generated DDL script is found under the EJB project as ejbModule/META-INF/Table.ddl.
- Run the DDL script against your target database to create the tables and associations.
To create an access bean:
- In the Project Explorer view, expand AuctionEJB to view the Onlineitem EJB.
- Right-click Onlineitem and select New > Other > EJB > Access Bean. Click Next.
- In the Add an Access Bean wizard, ensure that Data class is selected.
Data classes provide the data storage and access methods for cacheable enterprise
bean properties.
- Click Next and ensure that AuctionEJB is specified in the EJB
Project field.
- In the Enterprise Beans table, select the Onlineitem check
box and click Next.
- Select the Onlineitem bean in the Enterprise beans text area.
- In the Interfaces to use group, click the Remote radio button.
- In the Access bean name field, the default access bean name OnlineitemData appears.
Ensure that com.acme.ejb is specified in the Package name field.
- Ensure that all of the check boxes in the Attribute helpers list
box are selected.
- Click Finish. The new access bean named OnlineitemData is generated.
(Also, an EJB factory class is also automatically generated that is named
OnlineitemFactory. OnlineitemFactory provides the means for creating references
to enterprise bean remote objects).
To create a session bean:
- In the Project Explorer view, expand AuctionEJB.
- Right-click the Deployment Descriptor and select New > Enterprise
Bean. The enterprise bean creation wizard opens.
- Ensure that the EJB project field is set to AuctionEJB.
- Select the Session bean radio button.
- In the Bean name field, type ItemHelper and click Next.
- Check the Session type is set to Stateless. Ensure that
Container is selected as the Transaction type.
- Ensure the fields on the Enterprise Bean Details page are filled in with
the following values:
- Bean class: com.acme.ejb.ItemHelperBean
- Remote home interface:com.acme.ejb.ItemHelperHome
- Remote interface: com.acme.ejb.ItemHelper
- Click Finish. A session bean named ItemHelper is created in the
AuctionEJB project, which will be used to hold the application's business
logic and serve as a front end for the Onlineitem CMP entity bean.
In this section, you add your business logic to the session bean and then
promote the bean to the remote interface. The remote interface defines the
business methods that can be called by a client. The business logic consists
of four public methods:
- create Registers a new item for sale in the auction. The method
ensures that the business rules are enforced, such as ensuring that the value
of the minimum opening bid is less than the appraised value of the item.
- findByValue Searches the auction database for all items that have
a value less than the value specified as the search criteria.
- makeBid Bids for an item and ensures that all of the business rules
are met, such as ensuring that the current bid value is greater than the
previous bid value.
- reserveKeys A utility method that reserves a block of keys so that
when new items are submitted for sale, their entity key values can be assigned
locally.
To save you the effort of typing in the business methods by hand, the business
methods are provided for you in a .java file, which is contained in a zipped
project that you need to import. The next section shows you how to complete
the following tasks:
- Create a simple project to hold the contents of the zipped project that
you will import. Simple projects are generic projects that contain files
and folders.
- Import the zipped project
- Import the supporting classes from the zipped project and copy the business
methods to the session bean
- Add a finder method to obtain an entity bean instance from the dreamauc
database.
To create a project to hold the contents of the zipped project that you will
import:
- From the File menu, select New > Project.
- In the New Project wizard, expand Simple and select Project. Click Next.
- In the Project name field, type AuctionSamples.
- Click Finish. The project AuctionSamples is added to the workbench.
To import the zipped project:
- From the File menu, select Import to open the Import wizard,
then select Zip file and click Next.
- Beside the From zip file field, click Browse and then navigate
to the following file and select it (where install_path is the directory
where you have installed IBM Rational Developer):
install_path\eclipse\plugins\com.ibm.etools.weblogic.scenario.auction.doc\AuctionSample.zip
- Click Open.
- Beside the Into folder field, click Browse and select the AuctionSamples folder,
then click OK.
- Click Finish. The files contained in AuctionSample.zip are imported
into the AuctionSamples project.
To import the supporting classes from the zipped project:
- From the File menu, select Import to open the Import wizard
again, then select Zip file and click Next.
- Beside the From zip file field, click Browse and then navigate
to the following file and select it (where workspace_path is the directory
where you have installed your IBM Rational Developer workspace):
workspace_path\workspace\AuctionSamples\setup\Server-support.zip
- Click Open.
- Beside the Into folder field, click Browse and expand AuctionEJB,
then select ejbModule and click OK.
- Click Finish. The files contained in Server-support.zip are imported
into the ejbModule folder. (Any errors that appear in the Problems view will
eventually be resolved as you continue walking through the instructions.)
To copy the business methods to the session bean:
- In the Project Explorer view, expand AuctionSamples and the setup folder, then
double-click ItemHelperBean.java to open the source editor.
- In the editor, copy the entire contents of the class to the clipboard,
then close the editor.
- Expand AuctionEJB, Deployment Descriptor, Session Beans,
and ItemHelper, then double-click ItemHelperBean. The class
opens in the Java editor.
- In the editor, replace the entire contents of the class by pasting in the
contents that you copied to the clipboard.
- Click File > Save to save the revised source
code. (Any errors that appear in the Problems view will eventually be resolved
as you continue following the instructions.)
- In the Outline view, expand ItemHelperBean and select the create, findByValue, makeBid,
and reserveKeys methods together:

- Right-click the methods and select Enterprise Bean > Promote to Remote
Interface.
Notice the R label decoration appears beside the method names in the Outline
view to indicate that these are remote methods.
(Optional) You can browse the source code for these four methods to give
you an idea of how to add business logic to an application.
- Close the editor.
- In the Project Explorer view, double-click the ItemHelper class. The
source editor opens.
- Type (or copy and paste) the following code fragment into the ItemHelper
source code immediately after the opening curly brace:
public static final int ERROR_KEY = -1;
- In the editor, click File > Save ItemHelper.java to save the
updates and then close the editor.
To add a finder to the Onlineitem CMP bean:
- In the Project Explorer view, expand AuctionEJB and double-click
Deployment Descriptor.
- Click the Beans page, and select Onlineitem.
- Scroll down to the Queries section and click Add. The Add Finder
Descriptor wizard opens.
- Click the New radio button for the method.
- Click the find method radio button for the method type.
- Click the Remote check box for the type and uncheck Local.
- In the Name field, type findByValue.
- Click the Add button beside the Parameters list box. The Add Method
Parameter dialog box opens.
- In the Name field, type value.
- In the Type field, select long and click OK.
- In the Return type field, select java.util.Collection and
click Next.
- Type the following string into the Query statement text area and
click Finish:
select object(o) from Onlineitem as o where o.value <=?1
In the string, value is the name of a column in the Onlineitem
table and ?1 represents the parameter that is passed into the
finder method, so the string specifies that you want all of the items in
the auction that are less than or equal to the amount that is passed in.
- Click File > Save to save the changes,
then close the deployment descriptor editor.
To set up the JNDI bindings for the EJBs:
- In the Project Explorer view, expand AuctionEJB and double-click
Deployment Descriptor.
- View the WebLogic page.
- In the left pane of the editor, select Onlineitem.
- Change the JNDI Name field to com/acme/ejb/OnlineitemHome.
- Change the Local JNDI Name field to com/acme/ejb/OnlineitemLocalHome.
- Change the Data Source Name field to jdbc/dreamauc.
- In the left pane of the editor, select ItemHelper.
- Change the JNDI Name field to com/acme/ejb/ItemHelperHome.
- Save and close the editor.
In this section, you create a WebLogic server and configure it so that it
can work with the auction application and the auction database.
To create a WebLogic server:
- In the J2EE perspective, right-click in the Servers view and select New > Server.
- The New Server wizard opens. This wizard will create a new server that will use your specified WebLogic server runtime.
- In the Host name field, type the name or IP address of the machine hosting the server.
- In the Server type list, select the desired version and type of WebLogic Server (e.g. WebLogic v8.1 Local Server).
- If the selected server has more than one server runtime defined, choose the runtime to use in the Server runtime drop-down list.
- Click Next. If the selected WebLogic server type does not have a server runtime predefined in Preferences, a page will be presented for you to create the runtime. One should have been created in the Install IBM Rational Deployment Toolkit for WebLogic Server section of "Preparing for the Online Auction sample application". Note that this page will not be displayed if a server runtime was already created beforehand.
- Click Next. Fill in all the WebLogic Server settings. Ensure that the correct WebLogic Server administrator username and password is in the Username and Password fields.
- Click Finish. The new WebLogic server will appear in the Servers view.
To configure the server classpath:
- In the Servers view, double-click the WebLogic server to open the Server Editor.
- At the bottom of the editor, click the Classpath tab.
- In the editor, click Add External Jars and add the JAR containing
the DB2 driver classes. For example:
C:\Program Files\IBM\SQLLIB\java\db2java.zip
C:\Program Files\IBM\SQLLIB\java\db2jcc.zip (for DB2 8.1)
- Similarly, add the JARs containing IBM Rational Developer classes required to
run the the auction application on the WebLogic server (where install_path is the directory where you have installed IBM Rational Developer).
install_path\eclipse\plugins\com.ibm.etools.dbjars_6.0.0\jars\dbbeans.jar
install_path\runtimes\base_v6_stub\lib\ivjejb35.jar
- Click File > Save to save your changes.
Note: The exact paths for the JARs may vary according to where you
have installed DB2 and IBM Rational Developer.
Set up the database connection pool and data source for the auction database (Note: The steps below are specific to WebLogic Server version 7.0, but the general steps and information can be applied to versions 6.1 and 8.1.):
- In the Servers view, right-click on the WebLogic server and
select Start. This will start the WebLogic server; it
may take a few moments for the server to start.
- After the WebLogic server has started, view the Overview page of the
server editor (used in the previous steps).
- Click the Launch WebLogic Server console button in the editor.
- Login using the WebLogic Server administrator username and password. The
WebLogic Server home page will now be displayed in a browser window.
- Under the Services Configurations section, click Connection Pools to
configure a new connection pool using the following information:
Name: DreamAucConnectionPool
URL: jdbc:db2:DREAMAUC
Driver Classname: COM.ibm.db2.jdbc.app.DB2Driver
Properties: user=xxx;password=yyy where xxx is the user
name to connect to the database with (e.g. db2admin) and yyy is the password
to connect with
- Click Create and then select the Targets tab to enable the
connection pool for the target server.
- Navigate back to the homepage by clicking the Home icon in the top-right
corner of the page.
- Under the Services Configurations section, click Tx Data Sources or
(Data Sources in WLS 8.1) to configure a new JDBC TX Data Source using
the following information:
Name: DreamAucDataSource
JNDI Name: jdbc/dreamauc
Pool Name: DreamAucConnectionPool
- Click Create and then select the Targets tab to enable the
connection pool for the target server.
- Close the WebLogic Server console.
Now you need to test your business methods using the universal test client.
First you will launch the server on the ItemHelper bean, which will start the
universal test client:
- In the Project Explorer view, expand EJB Projects, AuctionEJB,
Deployment Descriptor, Session Beans, and
then select ItemHelper.
- Right-click ItemHelper and select Run > Run on Server to start
the server. The Server Selection wizard appears.
- Click the Choose an existing server radio button. Select the WebLogic server and
click Next.
- Add the Auction enterprise application project to the server by moving it to the right pane.
- Click Finish.
- It may take a moment or two for the test client to appear, since all of
the following tasks are being performed automatically:
- Publishing the application to the test server
- Configuring the test server
- Starting the test server
- Starting the test client
- Starting the Web browser
Now you will invoke methods and pass parameters to objects to place a bid.
- In the Universal Test Client, click JNDI Explorer to open the JNDI Explorer.
- On the JNDI Explorer page, in the JNDI Name field, type com/acme/ejb/ItemHelperHome.
- In the left left pane, expand ItemHelper and ItemHelperHome,
then click the ItemHelper create() link. This prepares the test client
to invoke the create method.
- In the Parameters pane, click Invoke to create and return a new
ItemHelper object. The ItemHelper object is returned in the lower half of
the Parameters pane:
- Click Work with Object. This adds the ItemHelper instance to the
left pane.
- In the left pane, expand ItemHelper (1) and click the Status
makeBid method link.
- In the Parameters pane, expand the parameters and type the following values
in the Value column:
- java.lang.Integer: 1
- java.lang.Long: 20000
- java.lang.String: Gary
- int: 1

The values specified for the parameters (which you can view in the source
code) have the following interpretations:
- 1 -- The item ID
- 20000 -- A bid of $200.00
- Gary -- The name of the bidder
- 1 -- The type of currency
- Click Invoke. A return code of 0 indicates that the method completed
successfully. You have just made your first bid!
Next, you will use the JNDI Explorer to find the object that you just bid
on.
- Click JNDI Explorer to open the JNDI Explorer.
- On the JNDI Explorer, in the JNDI Name field, type com/acme/ejb/OnlineitemHome.
- In the left pane, expand OnlineitemHome and click the Onlineitem
findByPrimaryKey(OnlineitemKey) link.
- In the Parameters pane, expand com.acme.ejb.OnlineitemKey and OnlineItemKey. Itemtypeid
appears in the Parameters column.
- In the Value field for the itemtypeid row, type 1 and click Invoke.
(In these steps, you are creating a new key and then passing the key into
the findByPrimaryKey method.)
- Click Work with Object. This places the item that you found in the
previous step in the left pane.
- In the left pane, expand Onlineitem and click the String getLastbidder() method.
- In the Parameters pane, click Invoke.
- Ensure that the resulting string is correct. It should be the name of the
bidder (Gary).
- If you want, you can continue to explore the features of the test client
by invoking more methods.
- When you are finished exploring, in the J2EE perspective, click the Servers tab
to switch to the Servers view.
- Select the WebLogic server and then click
the Stop toolbar button.
- Close the browser session where the Universal Test Client is running.
In this optional section, you configure your workspace with the location of
the team server. (This section assumes that you either have access to a CVS
server or you have already installed a CVS server for yourself using the instructions
in the topic "Preparing for the Online Auction sample application").
- Open the CVS Repository Exploring perspective (Window > Open Perspective > Other > CVS
Repository Exploring).
- Position your mouse pointer in the CVS Repositories view, then right-click
and select New > Repository Location. The Add CVS Repository wizard
appears. (To determine the actual values that you need to specify in the
wizard, you will probably need to talk to your CVS administrator.)
- In the Host field, type the host name or IP address of the team
server.
- In the Repository path field, type the fully qualified directory
name of the CVS repository on the server. For example:
D:\CVS\CVSROOT
- In the User field, type in your team server user name.
- In the Password field, type in your CVS password
- In the Connection type field, ensure that the correct connection
type is selected:

- Click Finish.
To prevent the class files from being stored in CVS, and save space in the
repository:
- From the main menu, click Window > Preferences > Team > Ignored
Resources.
- Click the Add button beside the Ignore Patterns pane. The Enter
Ignore Pattern dialog box opens.
- Type *.class and click OK.

- Click OK on the Preferences page to save your changes.
You can specify label decorations to appear for CVS resources, to show CVS
specific information on resources under CVS control. To display CVS label decorations:
- From the main menu, click Window > Preferences > Workbench > Label
Decorations.
- In the Available label decorations list box, click the CVS check
box.
- Click OK on the Preferences page to save your changes.
In this optional section, you learn how to version your application. (This
section assumes that you either have access to a CVS server or you have already
installed a CVS server for yourself using the instructions in the topic "Preparing
for the Online Auction sample application").
- Switch to the J2EE perspective.
- In the Project Explorer view, select the Auction project.
- Right-click and select Team > Share Project. The Share Project
wizard opens.
- Select CVS and click Next.
- Select the existing repository and click Next.
- Click the Use project name as module name radio button and click Next.
- Click Finish to import the project into the CVS repository. The
Synchronize view opens.
- In the Structure Compare pane, right-click Auction and then select Commit.
- You are prompted to add the resources to version control. Click Yes.
(If you want, you can enter a comment in the next dialog box when prompted.)
- Repeat steps 1-9 for each of the AuctionEJB and AuctionWeb projects. The
server is updated with a file structure that matches the structure you have
in the local file system and the files on the server are automatically compared
to the files in the local file system.
- Switch to the CVS Repository Exploring perspective.
- In the CVS Repositories view, click the Refresh View toolbar button.
Expand the connection and expand HEAD.
- Select the Auction, AuctionEJB, and AuctionWeb projects
together, then right-click and select Tag as Version. This causes
the server to associate the same tag for all the files in these three projects
on the server. The Tag Resources dialog box appears.
- In the Please enter a version tag field, type V1 and click OK.
- In the CVS Repositories view, expand Versions and then expand Auction to
see the new version.
In this optional section, you learn how to load the application into a different
IBM Rational Developer workspace that resides on a remote machine, such as a Web
designer's machine. If you don't have access to a remote machine, instructions
are provided for simulating the experience by opening up a second workspace
on your own local machine. In this section and the following section, the second
workspace is referred to as the "Web designer's workspace." (This section assumes
that you either have access to a CVS server or you have already installed a
CVS server for yourself using the instructions in the topic "Preparing for
the Online Auction sample application".)
- If you are using a remote machine, follow the instructions given previously
for installing DB2 on the remote machine and running the DB2 script that
is used to create the required database tables.
- If you do not have access to a remote machine and you want to open up a
second workspace on your local machine instead, complete the following three
steps:
- Close your current workspace by exiting IBM Rational Developer.
- Start IBM Rational Developer. You are prompted to specify a directory for
your workspace. Type the location of a new workspace. For example:
workspace_path\workspace2
IBM Rational Developer opens with the new workspace. None of the resources that
you created in your other workspace are currently visible.
- Open the CVS Repository Exploring perspective.
- Position your mouse pointer in the CVS Repositories view, then right-click
and select New > Repository Location. The Add CVS Repository wizard
appears. (To determine the actual values that you need to specify in the
wizard, you will probably need to talk to your CVS administrator.)
- In the Host field, type the host name or IP address of the team
server.
- In the Repository path field, type the fully qualified directory
name of the CVS repository on the server. For example:
D:\CVS\CVSROOT
- In the User field, type in your team server user name.
- In the Password field, type in your CVS password.
- In the Connection type field, ensure that the correct connection
type is selected and click Finish.
- Add CVS label decorations as previously described in the Set up the team
environment section.
- The default settings in IBM Rational Developer are set to prune empty directories
in CVS. To disable this setting, from the main menu, click Window > Preferences > Team > CVS .
- Clear the Prune empty directories check box and click OK to
exit the Preferences page.
- In the CVS Repositories view, expand the new repository node and expand HEAD,
then select Auction, AuctionEJB, and AuctionWeb together
and right-click and select Check out As Project. This adds the projects
to the Web designer's workspace.
To create and configure a WebLogic Server, see the section Create a server and add a data source .
In this section, you add a Web front end to your application that will include
the following functions:
- Searching for online items (based on a specified value)
- Obtaining details of a particular online item
- Registering an item for sale in the auction
- Bidding for an item
The OnlineItemData access bean will hold the information for an item.
To save you time, the Web front end is already provided for you in a WAR file,
which contains the artwork, JSP files, and servlets.
To add the Web front end:
- If you completed the steps in the previous section Add shared projects
to another workspace, then remain in your current Web designer's workspace
to complete the steps in this section. However, if you did not complete the
steps in the "Add shared projects to another workspace" section, you should
continue to use the workspace that you have been using up to this point in
the tutorial.
- If you are working in the Web designer's workspace rather than in the original
developer's workspace where you began the tutorial, then complete the following
steps:
- From the File menu, select New > Project.
- In the New Project wizard, expand Simple and select Project. Click Next.
- In the Project name field, type AuctionSamples.
- Click Finish. The project AuctionSamples is added to the workbench.
- From the File menu, select Import to open the Import wizard,
then select Zip file and click Next.
- Beside the From zip file field, click Browse and then navigate
to the following file and select it (where install_path is the directory
where you have installed IBM Rational Developer):
install_path\eclipse\plugins\com.ibm.etools.weblogic.scenario.auction.doc\AuctionSample.zip
- Click Open.
- Beside the Into folder field, click Browse and select the AuctionSamples folder,
then click OK.
- Click Finish. The files contained in AuctionSample.zip are imported
into the AuctionSamples project.
- From the File menu, select Import to open the Import wizard,
then select WebLogic WAR file and click Next. A Web archive (WAR) file
is a packaged Web application that is deployed on a Web server. A Web application
is a group of HTML pages, JSP pages, servlets, and other resources, along
with source files that can be managed as a single unit.
- Beside the WAR File field, click Browse and then navigate
to the following WAR file and select it (where workspace_path is the
path where you installed the IBM Rational Developer workspace):
workspace_path\workspace\AuctionSamples\setup\AuctionWeb.war
- In the Web project field, select the AuctionWeb project from the drop-down list.
- Select the Overwrite existing resources without warning check box.
- Click Finish. The WAR file is imported into the AuctionWeb project.
Any errors or warnings that appear in the Problems view will be resolved as you
complete the instructions
- To set the module dependency for the AuctionWeb project to the AuctionEJB
project, right-click the AuctionWeb project and select Properties.
The Properties page opens.
- On the left frame of the Properties page, click Java JAR Dependencies.
- In the Available dependent JARs list table, click the AuctionEJB.jar check
box and click OK. This enables the Web project to access the classes
in the EJB project at run time.
- If you completed the optional Set up the team environment and Version
the application sections, then complete the following steps:
- In the Project Explorer view, right-click the AuctionWeb project,
then select Team > Synchronize with Repository. The Synchronize
view opens.
- In the Structure Compare pane, right-click AuctionWeb and then
select Commit.
- You are prompted to add the resources to version control. Click Yes.
(If you want, you can enter a comment in the next dialog box when prompted.)
- If you used a second workspace (the Web designer's workspace) to complete
the steps in this section, you now have a fully functioning application and
you could use the various IBM Rational Developer tools to enhance the application.
At this point in the tutorial you should now close the second workspace and
open your original IBM Rational Developer workspace by exiting and
restarting IBM Rational Developer with your original workspace.
To run the application in the test environment:
- If you completed the steps in the section Add shared projects to another
workspace, then complete the following two steps:
- Switch to the J2EE perspective. In the Project Explorer view, right-click AuctionWeb and
select Team > Synchronize with Repository.
- In the Structure Compare pane, right-click AuctionWeb and select Update
from Repository. This moves all of the work that was done in the
Web designer's workspace into the original developer's workspace.
- Right-click the AuctionWeb project and select Debug > Debug on Server.
The Server selection wizard opens.
- Click the Choose an existing server radio button. Select the WebLogic server and
click Next.
- Add the Auction enterprise application project to the server by moving it to the right pane.
- Click Finish.
- The Debug perspective opens. The entire application is automatically deployed
and the Online Auction home page opens up in the browser window (which may
take a moment or two). The URL is http://localhost:7001/AuctionWeb.
Now that you have the application running on the test WebLogic server, you can set
breakpoints and debug the application while it is running.
To learn how the business methods work, such as the makeBid method:
- In the Project Explorer, expand AuctionEJB, ejbModule, and com.acme.ejb,
then double-click ItemHelperBean.java to open the source editor.
- Set a breakpoint beside the following line in the makeBid method (and ensure
that you put it in the makeBid method, since the line also appears in other
methods):
Status status = new Status();
- Switch back to Browser and then click the round Bid button
beside one of the flower items for sale.
- In the Your Name field, type your name.
- In the Your Bid field, type 250 and click the round Bid button.
- In the Debug view, expand the suspended thread that has the + symbol beside
it, then click the ItemHelperBean.makeBid line.
- Examine some variables in the Variables view.
- In the Debug view, single-step through some code by clicking the Step
Over icon.
- Remove the breakpoint that you set in the source code.
- In the Debug view, click the Resume icon.
- Close the open files and the Web browser.
- Switch to the J2EE perspective and click the Servers tab to open
the Servers view.
- Select the WebLogic server and then click
the Stop toolbar button.
- If you plan to run the ready-made sample application (as described in Part
1) after building the sample application for yourself from scratch, then
you need to remove the Auction project from the server configuration by completing
the following steps:
- In the Servers view, right-click the WebLogic server and select Add and remove projects.
- Remove Auction from the Configured projects list and click Finish.
(Note that if you make changes to your enterprise bean code, you will need
to republish to the server.)
Congratulations! You have built the Online Auction sample application and
run it in the IBM Rational Developer test environment. You learned how to create
various types of enterprise beans that hold the business logic of the application,
create and configure servers that connect to a database, test the business
methods in the test client, work in a team environment using a CVS repository,
and test and debug the application in a test environment.