If you deployed the Alice's World page (Appendix C: About the Example Applications), you have an idea of the steps involved in deployment. If you haven't, you should do so now because the Metric Converter application expects to return to that page. We are going to go through the deployment process step by step for both the Enterprise JavaBean and the Web component here. For the other examples, I recommend that you copy the .ear file from the associated prod directory, open it in deploytool and deploy from that (meaning, start at the sections labeled Deployment), unless you want more deployment practice. Another good way to practice is to copy an application directory to one of your own, then create the application from scratch with a new name, using the original .ear file for reference.
The MetricCvtBean deployment:
-
Start J2EE and
deploytool.
Create new application
-
From the menu, select File, New, Application.
-
Browse to the MetricCvt folder.
-
Key MetricCvt.ear for the file name.
-
Click New Application.
-
Application Display name is MetricCvt by default.
-
Click OK.
Create new Enterprise JavaBean component
-
Ensure that Application MetricCvt is selected.
-
From the menu, select File, New, Enterprise Bean — Intro display appears, click Next.
-
Select Create New JAR File In Application.
-
Ensure that MetricCvt is selected in the drop down menu.
-
In JAR Display Name, key MetricCvtJAR.
-
Click Edit.
-
Select the .class files that comprise the bean. These are:
MetricCvtBean.class
MetricCvtConstants.class
MetricCvtRemote.class
MetricCvtRemoteHome.class
-
Click Add; click OK; click Next.
-
Under Bean Type, click Session and Stateless.
-
In the Enterprise Bean Class combo box, select the bean implementation: MetricCvtBean.
-
In Enterprise Bean Name, accept MetricCvtBean.
-
Select the corresponding interfaces in the combo boxes:
For Remote Home Interface, select: MetricCvtRemoteHome.
For Remote Interface, select: MetricCvtRemote.
-
Click Next. You may continue with Next to look at the additional displays until you get to Finish, or click Finish now. For this bean, there are no more entries.
-
MetricCvtJAR and MetricCvtBean now appear under MetricCvt.
-
Select MetricCvtJAR, then click the JNDI Names tab.
-
Under EJBs, key ejb/MetricCvtBean next to MetricCvtBean.
Deployment
All of the preceding has been set up for the deployment
descriptors. We can now actually deploy the bean:
-
Select MetricCvt.
-
Select Tools Deploy from the menu.
-
Under Object To Deploy, ensure that MetricCvt is selected.
-
Under Target Server, select localhost.
-
Select the Return Client JAR check box. While our Web component won't need it, any remote clients would use this JAR for the necessary RMI/IIOP stubs.
-
Ensure that the complete path shows for MetricCvtClient.jar in the Client JAR File Name field.
-
Select Save object before deploying.
-
Click Next.
-
Verify that the JNDI name is ejb/MetricCvtBean.
-
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 MetricCvt Enterprise JavaBean component is deployed.
The Metric Converter Web component deployment
-
Start J2EE and
deploytool.
Create new application
- From the menu, select File, New, Application.
-
Browse to the MetricCvt folder.
-
Key MetricCvtApp.ear in file name.
-
Click New Application.
-
Application Display name is MetricCvtApp by default.
-
Click OK.
Create new Web component
-
Ensure that Application MetricCvtApp is selected.
-
From the menu, select File, New, Web Component — Intro display appears, click Next.
-
Select Create New WAR File In Application.
-
Ensure that MetricCvtApp is selected in the drop down menu.
-
In WAR Display Name, key MetricCvtAppWAR.
-
Click Edit.
-
Select the .jsp file and the bean interface .class files needed for the JSP files compilation. These are:
index.jsp
MetricCvtConstants.class
MetricCvtRemote.class
MetricCvtRemoteHome.class
-
Click Add, Click OK, Click Next.
-
Select JSP for the type of Web component; click Next.
-
In the JSP filename combo box, select index.jsp.
-
In Web Component Name, allow the default — index.
-
Click Next. There are no Initialization Parameters. Click Next.
-
Under Component Aliases, enter "/index" (without quotes).
-
You may continue with Next to look at the additional displays until you get to Finish, or click Finish now.
-
MetricCvtAppWAR now appears under MetricCvtApp.
-
Select MetricCvtAppWAR, 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/MetricCvtBean");
So, in the Coded Name column, enter ejb/MetricCvtBean.
-
Accept Session for Type and Remote for Interface.
-
For Home Interface, enter MetricCvtRemoteHome.
-
In the Local/Remote Interface column, enter MetricCvtRemote.
-
Now select MetricCvtApp and click on the JNDI Names tab.
-
Under References, key ejb/MetricCvtBean for the JNDI name next to the ejb/MetricCvtBean Reference Name. 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 MetricCvtApp.
-
Select Tools, Deploy from the menu.
-
Under Object To Deploy, ensure that MetricCvtApp is selected.
-
Under Target Server, we are using localhost. Be sure that is selected.
-
Unselect the Return Client JAR check box. In this case, the JSP is the client.
-
Select Save object before deploying.
-
Click Next.
-
Verify that the JNDI name under References is ejb/MetricCvtBean; click Next.
-
Key "/MetricCvtApp" 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 MetricCvtApp Web component is deployed.
If you look in the MetricCvt folder, you will see that it now contains MetricCvt.ear, MetricCvtApp.ear, and MetricCvtClient.jar. To run MetricCvtApp, start your browser and enter http://localhost:8000/Alice. When the Alice's World home page appears, click on the "Alice's Metric Converter" 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 entering http://localhost:8000/MetricCvtApp, but the Done button expects to return to the home page, so you should start from there.