|
Home TOC Index |
|
Search
Feedback |
Building, Packaging, Deploying, and Running the Application
To build the Duke's Bank application, you must have downloaded and unzipped the tutorial bundle as described in Downloading the Examples. When you install the bundle, the Duke's Bank application files are placed in the following directory structure of the
j2eetutorialdirectory:/bank /dd - deployment descriptors account-ejb.xml app-client.xml customer-ejb.xml runtime-ac.xml runtime-app.xml tx-ejb.xml web.xml /src /com - component classes /sun/ebank/appclient /sun/ebank/ejb /sun/ebank/web /web - JSP pages, images /sql - database scripts create-table.sql insert.sqlTo simplify building, packaging, and deploying the Duke's Bank application, the tutorial bundle includes deployment descriptors, source code, and a
build.xmlfile that contains the automatedanttasks. If you haven't runantyet, please see How to Build and Run the Examples.After you compile the source code, the resulting class files will reside in the
j2eetutorial/bank/buildsubdirectory. When you package the components and the application, the resulting archive files are placed in thej2eetutorial/bank/jarsubdirectory.Adding Groups and Users to the Realm
To run the J2EE application and Web clients, you must add groups and users to the default security realm. To create the
CustomerandAdmingroups, add the user200to theCustomergroup, and add the useradminto theAdmingroup indeploytool:
- Select Tools
Server Configuration
- In the tree, select the Users node.
- Make sure that Default is selected in the Realm combo box.
- Click Add User.
- Click Edit Groups.
- Click Add.
- Enter
Customer.- Click Add.
- Enter
Admin.- Click OK.
- Enter
200for User Name: andj2eefor Password:- Select the
Customergroup from the Available Groups list.- Click Add.
- Click Apply.
- Enter
adminfor User Name andj2eefor Password.- Select the
AdminGroup from the Available Groups list.- Click Add.
- Click OK.
You can perform the same tasks with the
realmtoolcommand-line utility:
realmtool -addGroup Customerrealmtool -add 200 j2ee Customerrealmtool -addGroup Adminrealmtool -add admin j2ee AdminStarting the J2EE Server, deploytool, and Database
J2EE Server
j2ee -verboseDeploytool
After the J2EE server reports
startup complete, rundeploytool:
- If the
deploytoolutility is not running, launch it from the command line:deploytool- If
deploytoolis already running, reconnect to the J2EE server:Cloudscape
Start the Cloudscape database server:
cloudscape -startCompiling the Enterprise Beans
In a different window, go to the
j2eetutorial/banksubdirectory of the tutorial distribution and type this command:ant compile-ejbPackaging the Enterprise Beans
To package the enterprise beans, type the following:
ant package-ejbThe preceding command packages the class files and the deployment descriptors into the following EJB JAR files, which reside in the
j2eetutorial/bank/jarsubdirectory.account-ejb.jar customer-ejb.jar tx-ejb.jarWhen packaging a component in this chapter,
antmay report that it cannot find a file (such asaccount-ejb.jar) to delete. You may ignore these messages.Compiling the Web Client
To compile the Web client, go to the
j2eetutorial/bankdirectory of the tutorial distribution and execute the following:ant compile-webPackaging the Web Client
The Web client uses the Struts tag library discussed in The Example JSP Pages. Before you can package the Web client, you must download and install Struts version 1.0 from
http://jakarta.apache.org/builds/jakarta-struts/release/v1.0/Copy
struts-logic.tldandstruts.jarfromjakarta-struts-1.0/libtoj2eetutorial/bank/jar. Then change to thej2eetutorial/bankdirectory and type the following:ant package-webThis command packages the servlet class, JSP pages, JavaBeans component classes, tag libraries, and the Web application deployment descriptor into
web-client.warand puts this file inj2eetutorial/bank/jar.Compiling the J2EE Application Client
To compile the application client, go to the
j2eetutorial/banksubdirectory and run this command:ant compile-acPackaging the J2EE Application Client
- Go to the
j2eetutorial/bankdirectory and run this command:ant package-ac
- This command creates the
app-client.jarfile in thej2eetutorial/bank/jardirectory.- From the same directory, type the following:
ant setruntime-ac
- This command adds a runtime deployment descriptor
(j2eetutorial/bank/dd/runtime-ac.xml) toapp-client.jar.Packaging the Enterprise Archive File
- To create the Duke's Bank enterprise archive file, go to the
j2eetutorial/bankdirectory and run this command:ant assemble-app
- This command creates the
DukesBankApp.earfile in thej2eetutorial/bank/jardirectory.- From the same directory, type the following:
ant setruntime-app
- This command adds a runtime deployment descriptor (
j2eetutorial/bank/dd/runtime-app.xml)toDukesBankApp.ear.Opening the Enterprise Archive File
In
deploytool, open the EAR as follows:
- Select File
Open.
- Go to the
j2eetutorial/bank/jarsubdirectory.- Select
DukesBankApp.ear.- Click Open Object.
You should see the screen shown in Figure 18-8 in
deploytool:Figure 18-8 Duke's Bank Application Archives and Components
Reviewing JNDI Names
With
DukesBankAppselected, click the JNDI Names tab. The JNDI Name column is shown in Figure 18-9. The order may be a little different on your own display.A JNDI name is the name the J2EE server uses to look up enterprise beans and resources. When you look up an enterprise bean, you supply statements similar to those shown in the following code. The actual lookup takes place in the third line of code, in which the
getCustomerControllerHomemethod ofcom.sun.ebank.utilEJBGetteris called.EJBGetteris a utility class that retrieves a coded JNDI name fromcom.sun.ebank.util.CodedNames. In this example, the application client is looking up the coded name for theCustomerControllerremote interface:try { customerControllerHome = EJBGetter.getCustomerControllerHome(); customer = customerControllerHome.create(); } catch (Exception NamingException) { NamingException.printStackTrace(); } public static CustomerHome getCustomerHome() throws NamingException { InitialContext initial = new InitialContext(); Object objref = initial.lookup( CodedNames.CUSTOMER_EJBHOME);
BankAdmin(the display name for the main class of the application client) referencesejb/customerController, which is the coded name defined inCodedNamesfor theCustomerControllerremote interface.The JNDI name is stored in the J2EE application deployment descriptor, and the J2EE server uses it to look up the
CustomerControllerEJBbean. In Figure 18-9 you see thatCustomerControllerEJBis mapped to the same JNDI name as isejb/customerController. It does not matter what the JNDI name is, as long as it is the same name for the remote interface lookup as you use for its corresponding bean. So, looking at the table, you can say that the application client (BankAdmin) looks up theCustomerControllerremote interface, which uses the JNDI name ofMyCustomerController, and the J2EE server uses theMyCustomerControllerJNDI name to find the correspondingCustomerControllerEJBobject.The other rows in the table have the mappings for the other enterprise beans. All of these beans are stored in the JAR files you added to the J2EE application during assembly. Their implementations have coded names for looking up either other enterprise beans or the database driver.
The JNDI name for the database driver is
jdbc/Cloudscape. This name is the default coded name supplied in a configuration file of your J2EE SDK installation. For more information, see the Configuration Guide of the J2EE SDK.Mapping the Security Roles to Groups
To map the
BankAdminrole to theAdmingroup and theBankCustomerrole to theCustomergroup:
- In
deploytool, selectDukesBankApp.- In the Security tab, select the
BankAdminrole from the Role Name list.- Click Add.
- In the User Groups dialog box, select the
Admingroup in the Group Name list.- Click OK.
- In the Security tab, select the
BankCustomerrole from the Role Name list.- Click Add.
- In the User Groups dialog box, select the
Customergroup in the Group Name list.- Click OK.
- From the main menu, select File
Save.
Figure 18-10 shows the
BankCustomerrole selected and theCustomergroup to which it is mapped.Figure 18-10 BankCustomer Role Mapped to Customer Group
Deploying the Duke's Bank Application
- Select the
DukesBankAppapplication.- Select Tools
Deploy.
- Select the checkbox labeled Return Client Jar. By default, the directory for the returned JAR file is the same as where the EAR file is stored. The default name of the client JAR file is the application name with
Client.jarappended, in this case,DukesBankAppClient.jar.- Click Finish.
Creating the Bank Database
You have to create and enter data into the appropriate tables so that the enterprise beans have something to read from and write to the database. To create and populate the database tables, in a terminal window go to the
j2eetutorial/bankdirectory and type the following commands:Running the J2EE Application Client
To run the J2EE application client:
- In a terminal window, go to
j2eetutorial/bank/jar.- Set the
APPCPATHenvironment variable toDukesBankAppClient.jar.- To run the English version of the client, execute the following command:
runclient -client DukesBankApp.ear -name BankAdmin- To run the Spanish version, include the
eslanguage code:runclient -client DukesBankApp.ear -name BankAdmin es
- The
DukesBankApp.earparameter is the name of the J2EE application EAR file, and theBankAdminparameter is the display name of the application client.- At the login prompts, type in
adminfor the user name andj2eefor the password. The next thing you should see is the application shown in Figure 18-11.Figure 18-11 BankAdmin J2EE Application Client
Running the Web Client
- Open the bank URL,
http://<host>:8000/bank/main, in a Web browser. If your J2EE server is running on the same host as your Web browser, replace<host>withlocalhost. To see the Spanish version of the application, set your browser language preference to any Spanish dialect.- The application will display the login page. Enter
200for the customer ID andj2eefor the password. Click Submit.- Select an application function: Account List, Transfer Funds, ATM, or Logoff. Once you have a list of accounts, you can get an account history by selecting an account link.
Note: The first time you select a new page, particularly a complicated page like an account history, it takes some time to display because the J2EE server must translate the page into a servlet class and compile and load the class.
If you select Account List, you will see the screen shown in Figure 18-12.
|
Home TOC Index |
|
Search
Feedback |