Tải bản đầy đủ (.doc) (4 trang)

Tài liệu Getting Started with EJB docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (99.77 KB, 4 trang )

Setting up J2EE
1. Install J2EE
2. Set up enviroment variables
JAVA_HOME
J2EE_HOME
CLASSPATH=.;%J2EE_HOME%\lib\j2ee.jar;%CLASSPATH%
3. Set up shortcut to start j2ee and deploytool in Editplus
j2ee –verbose
deploytool
Getting Started with EJB & J2EE
1. Creating the Enterprise Bean
The enterprise bean in our example is a stateless session bean called ConverterEJB.
The source code for ConverterEJB is in the /converter directory
To prepare, you should compile the remote interface (Converter.java), home
interface (ConverterHome.java), and the enterprise bean class (ConverterBean.java).
2. Starting the J2EE Server
To launch the J2EE server, open a terminal window and type this command:
(should use shortcut in Editplus)
j2ee –verbose
3. Starting the deploytool: (should use shortcut in Editplus)
deploytool
4. Creating the J2EE Application
• In deploytool, select File-> New-> Application.
• Click Browse.
• In the file chooser, navigate to folder /converter.
• In the File Name field, enter ConverterApp.ear.
• Click New Application.
• Click OK.
5. Packaging the Enterprise Bean
To start the New Enterprise Bean wizard, select File->New->Enterprise Bean.
The wizard displays the following dialog boxes.


1. Introduction dialog box
a. Read the explanatory text for an overview of the wizard's
features.
b. Click Next.
2. EJB JAR dialog box
a. Select the Create New JAR File In Application button.
b. In the combo box, select ConverterApp.
c. In the JAR Display Name field, enter ConverterJAR.
d. Click Edit.
e. In the tree under Available Files, locate the /converter
directory. Select the following classes from the Available Files
tree and click Add: Converter.class, ConverterBean.class, and
ConverterHome.class. Click OK.
f. Click Next.
3. General dialog box
a. Under Bean Type, select the Session radio button.
b. Select the Stateless radio button.
c. In the Enterprise Bean Class combo box, select ConverterBean.
d. In the Enterprise Bean Name field, enter ConverterEJB.
e. In the Remote Home Interface combo box, select
ConverterHome.
f. In the Remote Interface combo box, select Converter.
g. Click Next.
1. Transaction Management dialog box
a. Because you may skip the remaining dialog boxes, click
Finish.
6. Creating the Web Client
The Web client is contained in the JSP page /converter/index.jsp
7. Packaging the Web Client
To start the New Web Component wizard, select File->New->Web Component.

The wizard displays the following dialog boxes.
1. Introduction dialog box
a. Read the explanatory text for an overview of the wizard's
features.
b. Click Next.
2. WAR File dialog box
a. Select Create New WAR File In Application.
b. In the combo box, select ConverterApp.
c. In the WAR Display Name field, enter ConverterWAR.
d. Click Edit.
e. In the tree under Available Files, locate the /converter directory.
f. Select index.jsp and click Add.
g. Select Converter.class and click Add
h. Select ConverterHome.class and click Add
i. Click OK.
j. Click Next.
3. Choose Component Type dialog box
a. Select the JSP radio button.
b. Click Next.
4. Component General Properties dialog box
a. In the JSP Filename combo box, select index.jsp.
b. Click Finish.
8. Specifying the Web Client's Enterprise Bean Reference
When invoking the lookup method, the Web client refers to the home of an
enterprise bean: Object objRef = ic.lookup("java:comp/env/ejb/MyConverter");
You specify this reference as follows:
• In the tree, select ConverterWAR.
• Select the EJB Refs tab.
• Click Add.
• In the Coded Name column, enter ejb/MyConverter. Rất mong được sự quan

tâm thông cảm của Thầy giáo. Em xin chân thành cảm ơn thầy! Thưa thầy em
cho dù đã rất cố gắng nhưng bài tập vẫn còn rất nhiều thiếu xót do chưa hiểu
rõ bản chất của công nghệ. theo những hướng dẫn và sử dụng mã nguồn của
thầy giáo(nhưng do nhiều lí do nên việc đóng gói chưa thể hoàn thiện).
• In the Type column, select Session.
• In the Interfaces column, select Remote.
• In the Home Interface column, enter ConverterHome.
• In the Local/Remote Interface column, enter Converter.
9. Specifying the JNDI Names
Although the Web client refers to EJB as ejb/TheConverter, for the lookup method to
retrieve the home object, you must map the references in the code to the enterprise bean's
JNDI name. Although this mapping adds a level of indirection, it decouples the clients
from the beans, making it easier to assemble applications from J2EE components
To map the enterprise bean references in the clients to the JNDI name of the bean,
follow these steps.
1. In the tree, select ConverterApp.
2. Select the JNDI Names tab.
3. To specify a JNDI name for the bean, in the Application table
locate the ConverterEJB component and enter MyConverter in the
JNDI Name column.
4. To map the references, in the References table enter MyConverter in
the JNDI Name for each row
10. Deploying the J2EE Application
1. Select the ConverterApp application.
2. Select Tools Deploy.
3. In the Introduction dialog box, confirm that ConverterApp is shown
for the Object To Deploy and that localhost is shown for the Target
Server.
7. In the JNDI Names dialog box, verify the names you entered in the
previous section.

8. Click Next.
9. In the WAR Context Root dialog box, enter converter in the
Context Root field. When you run the Web client, the converter
context root will be part of the URL.
10. Click Next.
11. In the Review dialog box, click Finish.
12. In the Deployment Progress dialog box, click OK when the
deployment completes.
11. Running the Web Client
To run the Web client, point your browser at the following URL:
http://localhost:8000/converter

×