Download
FAQ History |
API
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 About the Examples. When you install the bundle, the Duke's Bank application files are located in the
<
INSTALL
>/j2eetutorial14/examples/bank/
directory:
/bank
- packaged Web client and J2EE application
/provided-jars
containing the enterprise beans and application client
/sql
- database scripts
/src
/com
- component classes/sun/ebank/appclient
/sun/ebank/ejb
/sun/ebank/util
/sun/ebank/web/web
- JSP pages, imagesAfter you compile the source code, the resulting files will reside in the
<
INSTALL
>/j2eetutorial14/examples/bank/build/
directory.Setting Up the Servers
Before you can package, deploy, and run the example, you must first set up the PointBase database server with customer and account data, and you must add some resources to the Application Server.
Creating the Bank Database
You 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, follow these steps:
- Start the PointBase database server.
- In a terminal window or command prompt, go to the
<
INSTALL
>/j2eetutorial14/examples/bank/
directory and execute the commandasant
create-db_common
. This task invokes the PointBase console tool library to execute the SQL contained in<
INSTALL
>/j2eetutorial14/examples/bank/sql/bank.sql
. The SQL statements in this file delete any existing tables, create new tables, and insert data. The first time the script is run the tables don't exist, so you will see SQL errors. You can just ignore them.Creating the JDBC Data Source
The Duke's Bank enterprise beans reference the database having the JNDI name
jdbc/BankDB
. That JNDI name must be mapped to a JDBC data source in the Application Server. You create the data source using the Admin Console following the procedures described in Creating a Data Source. When you create the JDBC data source, name itjdbc/BankDB
and map it toPointBasePool
.Adding Users and Groups to the File Realm
To enable the Application Server to determine which users can access enterprise bean methods and resources in the Web client, add users and groups to the server's file security realm using the Admin Console following the procedures described in Managing Users. Add the users and groups listed in Table 36-3.
Table 36-3 Duke's Bank Users and Groups User Password Group200
j2ee
bankCustomer
bankadmin
j2ee
bankAdmin
Compiling the Duke's Bank Application Code
To compile the enterprise beans, application client, and Web client, go to the
<
INSTALL
>/j2eetutorial14/examples/bank/
directory of the tutorial distribution and execute the commandasant
build
.Packaging and Deploying the Duke's Bank Application
The instructions that follow for packaging and deploying Duke's Bank assume that you are familiar with the deploytool procedures for packaging enterprise beans, application clients, and Web applications described in previous chapters of the tutorial. If after following these procedures you have trouble deploying or running the application, you can use the EAR provided in
<
INSTALL
>/j2eetutorial14/examples/bank/provided-jars/
to run the example.Packaging the Enterprise Beans
- Invoke the Enterprise Bean wizard for each entity bean in Table 36-4. For each bean, select Bean-Managed Persistence as the persistence management type and
java.lang.String
as the primary key class.The first time you invoke the wizard, create an EJB JAR module named
DukesBankEJBJAR
in<
INSTALL
>/j2eetutorial14/examples/bank/
. Add theejb
andutil
packages under<
INSTALL
>/j2eetutorial14/examples/bank/build/com/sun/ebank/
to the JAR.- For each entity bean, add a resource reference to a data source with coded name
jdbc/BankDB
. Set the Sun-specific JNDI name tojdbc/BankDB
. Because you have already added the JDBC resource to the Application Server, you should select the name from the drop-down menu.- For each entity bean, set the transaction attributes for all methods to
Required
, except for the methods listed in Table 36-5, which should be set toNot Supported
:- Invoke the Enterprise Bean Wizard for each of the stateful session beans in Table 36-6.
- For each session bean, add a resource reference to a data source with coded name
jdbc/BankDB
. Set the Sun-specific JNDI name tojdbc/BankDB
. Because you have already added the JDBC resource to the Application Server, you should select the name from the drop-down menu.- Add EJB references from the session beans to the local entity beans listed in Table 36-7.
- Save the module.
Packaging the Application Client
- Invoke the Application Client wizard.
- Create an application client module named
DukesBankACJAR
in<
INSTALL
>/j2eetutorial14/examples/bank/
.- Add the
appclient
,util
, andejb/exception
packages and theejb/*/*Controller*
home and remote interfaces (AccountController
,AccountControllerHome
,CustomerController
,CustomerControllerHome
,TxController
,TxControllerHome
) under<
INSTALL
>/j2eetutorial14/examples/bank/build/com/sun/ebank/
to the JAR.- Select
appclient.BankAdmin
as the application client main class.- Add EJB references to the session beans listed in Table 36-8.
Packaging the Web Client
- Create a
Dispatcher
servlet Web component using the Web Component wizard. Create a new Web module containing the componentDukesBankWAR
in<
INSTALL
>/j2eetutorial14/examples/bank/
.- Add content to the Web module.
- Add the
web
,util
, andejb/exception
packages and theejb/*/*Controller*
home and remote interfaces (AccountController
,AccountControllerHome
,CustomerController
,CustomerControllerHome
,TxController
,TxControllerHome
) under<
INSTALL
>/j2eetutorial14/examples/bank/build/com/sun/ebank
to the module.- Add the
template
directory, all the JSP pages, theWebMessages*.properties
files andtutorial-template.tld
under<
INSTALL
>/j2eetutorial14/examples/bank/build/
to the module.- In the Web module contents editor, drag the files
WebMessages*.properties
from the context root toWEB-INF/classes
.- Set the context root to
/bank
.- Add the
/accountHist
,/accountList
,/atm
,/atmAck
,/main
, /transferAck
,/transferFunds
, and/logoff
aliases to theDispatcher
component.- Add EJB references to the session beans listed in Table 36-9.
- Add a JSP property group named
bank
. The property group applies to the URL pattern*.jsp
. Add the include prelude/template/prelude.jspf
.- Add a context parameter named
javax.servlet.jsp.jstl.fmt.localizationContext
and valueWebMessages
.- Add a security constraint.
- Select Form Based as the user authentication method. The authentication settings are
file
for the realm name,/logon.jsp
for the login page, and/logonError.jsp
for the error page.- Add a security constraint and a Web resource collection. Use the default names provided by
deploytool
.- Add the URL Patterns
/main
,/accountList
,/accountHist
,/atm
,/atmAck
,/transferFunds
, and/transferAck
to the Web resource collection.- Select the
GET
andPOST
HTTP methods.- Add the security role
bankCustomer
.- Save the module.
Packaging and Deploying the Application
- Create a J2EE application named
DukesBankApp
in<
INSTALL
>/j2eetutorial14/examples/bank/
.- Add the
DukesBankACJAR
application client module toDukesBankApp
.- Add the
DukesBankEJBJAR
EJB module toDukesBankApp
.- Add the
DukesBankWAR
Web module toDukesBankApp
.- Add the security roles
bankAdmin
andbankCustomer
.- Add the following security settings for the enterprise beans.
AccountControllerBean
: In the Security tab, restrict access to users in thebankAdmin
security role for the methodssetBalance
,removeCustomerFromAccount
,setCreditLine
,setDescription
,removeAccount
,createAccount
,addCustomerToAccount
,setBeginBalance
, andsetType
. In the General tab, click the Sun-specific Settings button, and then click the IOR button in the General frame. In the As Context frame, set Required totrue
.CustomerControllerBean
: In the Security tab, restrict access to users in thebankAdmin
security role for the methodsgetCustomersOfAccount
,createCustomer
,getCustomersOfLastName
,setName
,removeCustomer
, andsetAddress
. In the General tab, click the Sun-specific Settings button, and then click the IOR button in the General frame. In the As Context frame, set Required totrue
.TxControllerBean
: In the Security tab, restrict access to users in thebankCustomer
security role for the methodsgetTxsOfAccount
,makeCharge
,deposit
,transferFunds
,withdraw
, andmakePayment
.- Start the Application Server.
- Map the
bankCustomer
role to thebankCustomer
group.- Map the
bankAdmin
role to thebankAdmin
group.- Save the application.
- Deploy the application. In the Deploy
DukesBankApp
dialog box, select the Return Client Jar checkbox.After you have packaged all the modules,
deploytool
should look like Figure 36-8.
Figure 36-8 Duke's Bank Modules and Components
Reviewing JNDI Names
With
DukesBankApp
selected, click the JNDI Names tab. The JNDI Name column is shown in Figure 36-9. The order may be a little different in your own environment.
Figure 36-9 Duke's Bank JNDI Names
A JNDI name is the name the Application 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.
try { customerControllerHome = EJBGetter.getCustomerControllerHome(); customer = customerControllerHome.create(); } catch (Exception namingException) { namingException.printStackTrace(); } public static CustomerControllerHome getCustomerControllerHome() throws NamingException { InitialContext initial = new InitialContext(); Object objref = initial.lookup( CodedNames.CUSTOMER_CONTROLLER_EJBHOME);The lookup takes place in the third line of code, in which the
getCustomerControllerHome
method ofcom.sun.ebank.utilEJBGetter
is called.EJBGetter
is 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 the
CustomerController
remote interface.BankAdmin
(the display name for the main class of the application client) referencesejb/customerController
, which is the coded name defined inCodedNames
for theCustomerController
remote interface.The JNDI name is stored in the J2EE application deployment descriptor, and the Application Server uses it to look up the
CustomerControllerBean
bean. In Figure 36-9 you see thatCustomerControllerBean
is 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 theCustomerController
remote interface, which uses the JNDI name ofCustomerControllerBean
, and the Application Server uses theCustomerControllerBean
JNDI name to find the correspondingCustomerControllerBean
object.The other rows in the table have the mappings for the other enterprise beans. All of these beans are stored in the JAR file you added to the J2EE application during assembly. Their implementations have coded names for looking up either other enterprise beans or the database driver.
Download
FAQ History |
API
Search Feedback |
All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.