Deployment for the Rock Survey application will look very similar to Deploying the Metric Converter Example. The major differences are the names, the fact that we are using a stateful session bean, and the fact that the bean and Web components are in the same EAR. Because we will deploy several versions of this application using components with the same name, we will use Survey1 for the Application EAR, WAR, and JAR files. Here are the directions:
The Survey1 application deployment:
- Compile the Java source files in the Survey1 directory,
or copy the .class files from the
prod folder.
- Start J2EE and
deploytool.
Create new application
-
From the menu, select File, New, Application.
-
Browse to the Survey1 folder.
-
Key Survey1App.ear for the file name.
-
Click New Application.
-
Application Display name is Survey1App by default; click OK.
Create new Enterprise JavaBean component
-
Ensure that Application Survey1 is selected.
-
From the menu, select File, New, Enterprise Bean —
Intro display appears; click Next.
-
Select Create New JAR File In Application.
-
Ensure that Survey1 is selected in the drop-down menu.
-
In JAR Display Name, key Survey1JAR.
-
Click Edit.
-
Select the .class files that comprise the bean. These are:
RockSurveyBean.class
RockSurveyConstants.class
RockSurveyData.class
RockSurveyRemote.class
RockSurveyRemoteHome.class
SurveyConstants.class
-
Click Add; click OK; click Next.
-
Under Bean Type, click Session and Stateful.
-
In the Enterprise Bean Class combo box, select the bean
implementation: RockSurveyBean.
-
In Enterprise Bean Name, key RockSurvey1Bean.
-
Select the corresponding interfaces in the combo boxes:
For Remote Home Interface, select: RockSurveyRemoteHome.
For Remote Interface, select: RockSurveyRemote.
-
Click Next, click Finish.
-
Survey1JAR and RockSurvey1Bean now appear under Survey1App.
-
Select Survey1JAR, then click the JNDI Names tab.
-
Under EJBs, key ejb/RockSurvey1Bean next to RockSurvey1Bean.
Create new Web component
-
Ensure that Application Survey1App is selected.
-
From the menu, select File, New, Web Component — Intro display appears; click Next.
-
Select Create New WAR File In Application.
-
Ensure that Survey1App is selected in the drop-down menu.
-
In WAR Display Name, key Survey1WAR.
-
Click Edit.
-
Select the files needed for the component. These are:
The images directory
index.jsp
RockSurvey.jsp
RockSurveyExit.jsp
SurveyWelcome.jsp
-
Click Add; click OK; click Next.
-
Select JSP for the type of Web component, then click Next.
-
In the JSP filename combo box, select index.jsp.
-
In Web Component Name, keep the default — index.
-
Click Next. There are no Initialization Parameters. Click Next.
-
Under Component Aliases, click Add, enter "/index" (without quotes).
-
Click Next; click Finish.
-
Survey1WAR now appears under Survey1App.
-
Select Survey1WAR, then select the EJB Refs tab and click Add.
-
When the Web client invokes the lookup method, it refers to the home of an enterprise bean like this:
Object objRef = ic.lookup("java:comp/env/ejb/RockSurveyBean");
So, in the Coded Name column, enter ejb/RockSurveyBean.
-
Accept Session for Type and Remote for Interface.
-
For Home Interface, enter RockSurveyRemoteHome.
-
In the Local/Remote Interface column, enter RockSurveyRemote.
-
At the bottom, select
ejb-jar-ic.jar#RockSurvey1Bean from the Enterprise Bean Name drop-down menu. Then click the JNDI Name button and select ejb/RockSurvey1Bean from the drop-down menu. This maps the actual JNDI name for the bean to the name used in the application code.
Deployment
We can now actually deploy the Web component:
-
Select Survey1App.
-
Select Tools, Deploy from the menu.
-
Under Object To Deploy, ensure that Survey1App is selected.
-
Under Target Server, we are using localhost. Be sure that is selected.
-
Select the Return Client JAR check box.
-
Select Save object before deploying.
-
Click Next.
-
Verify that the JNDI name under both Application and References is ejb/RockSurvey1Bean, then click Next.
-
Key "/Survey1App" in the context root.
-
Click Next, then Finish.
-
The Deployment Progress dialog will display. Wait until the progress bars are complete and the Cancel button changes to OK, then click OK.
The Survey1App application is deployed.
If you look in the Survey1 folder, you will see that it now contains Survey1App.ear and Survey1AppClient.jar. To run the Survey1App, start your browser and enter http://localhost:8000/Alice. When the Alice's World home page appears, click on the "Alice's Surveys - Take 1" link. The JSP must be compiled, so the first run will appear to take a while to load. You can also run the application by using the URL http://localhost:8000/Survey1App, but the Done button expects to return to the home page, so you should start from there.