How Do I Deploy Enterprise JavaBeans to IBM WebSphere?

An Oracle JDeveloper TechNote
February 2002

Content

Introduction

This TechNote describes in detail the requirements and steps to deploy Enterprise JavaBeans to IBM WebSphere 4.0.

This document was written for Oracle9i JDeveloper Release Candidate 2 and IBM WebSphere AEs 4.0.1 on Windows, although other versions of Oracle9i JDeveloper and/or IBM WebSphere should behave the same.

Starting WebSphere

The IBM WebSphere documentation includes more information on how to start and stop WebSphere. Here are the basic steps if you are using WebSphere with the IBM HTTP Server:

  1. Using the Services control panel applet, start both the IBM HTTP Server and IBM HTTP Administration services. The Services control panel applet is located in the Control Panel on Windows NT, and under the Administrative Tools folder under the Control Panel on Windows 2000/XP.
  2. Open a command prompt and change directory to the bin directory under your WebSphere installation. By default, this will be C:\WebSphere\AppServer\bin.
  3. Execute the batch file startServerBasic.bat, this will launch WebSphere using the console window for diagnostic messages, this is more convenient than referring to the log files for stdout and stderr to see messages from WebSphere.

You will know that WebSphere has been fully initialized when you see the phrase Server open for e-business in the console window.

Server

Creating a Simple EJB

Our Session Bean will be named MySessionEJB, will contain one field called info, and have a corresponding getInfo and setInfo method on the bean.

Use the following steps to create a New Stateless Session Bean. 

  1. From the Main Menu, choose File | New.
  2. In the New dialog that appeared, select the Projects category.
  3. Select the Workspace Item on the right side of the dialog and click OK.
  4. Accept the defaults for the New Workspace dialog by clicking OK.
  5. Accept the defaults for the New Project dialog by clicking OK.
  6. In the navigator, right-click the newly created project node, and select New from the context menu.
  7. Select the Enterprise JavaBeans category on the left of the dialog.
  8. Select the Stateless Session Bean item on the right of the dialog and click OK.
  9. Immediately click Finish. This will create a default Session Bean called MySessionBean.
  10. In the navigator, right-click the MySessionEJB node and select EJB Class Editor from the context menu.
  11. In the EJB Class Editor, select the Fields tab.
  12. Click the Add button at the top of the editor.
  13. In the Field Name text field, enter "info", and click OK.
  14. Choose File | Save All to save your work.
  15. Close the EJB Class Editor.

Creating the Test Client for WebSphere

We will create a simple Java Server Page (JSP) to test the Enterprise JavaBean. The JSP will look up an instance of our SessionBean (MySessionBean), and set the "info" property on the bean. It will then display the value of the "info" property using a call to "getInfo".

Here are the steps to create a simple JSP to test our EJB:

  1. In the navigator, right-click the Project node and choose New.
  2. Select the category Web Objects.
  3. Select the item JSP.
  4. On the New JSP dialog that has appeared, change the name to index.jsp and click the OK button.
  5. In the navigator, double click the newly created index.jsp node.
  6. Replace the text of the JSP with the following:
<%@ page contentType="text/html;charset=windows-1252"%>

<%@ page import="javax.naming.*,mypackage.*" %>

 <HTML>
 <HEAD>
 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
 <TITLE>
 Hello World
 </TITLE>
 </HEAD>
 <BODY>
 <%
      Context ctx = new InitialContext();
      Object ref = ctx.lookup( "MySessionEJB" );
      MySessionEJBHome mySessionEJBHome = ( MySessionEJBHome ) 
          javax.rmi.PortableRemoteObject.narrow( ref, MySessionEJBHome.class );
      MySessionEJB mySessionEJB = mySessionEJBHome.create( );

      mySessionEJB.setInfo( "Hello World" );
      out.println( mySessionEJB.getInfo() );
%>
</BODY>
</HTML>
     

Testing the EJB locally with the embedded OC4J

It is quite simple to test our JSP which invokes an EJB in the embedded OC4J that is included with Oracle9i JDeveloper. Here are the steps:

  1. In the navigator, right-click the node index.jsp and select Run index.jsp from the context menu.
  2. Your web browser should be launched on the URL to see the JSP page. The page will simply display " Hello World".

Notice the URL which is used in your web browser. The only difference in this URL and the one to use with WebSphere is the port number. By default the embedded OC4J instance uses port 8988 and WebSphere uses ports 80 and 9080 by default for user applications.

Creating the Deployment Profiles

We must create three deployment profiles before we can deploy our J2EE application to WebSphere. They are as follows:

  1. J2EE EJB Module (EJB JAR file)
  2. J2EE Web Module (WAR file)
  3. J2EE Application (EAR file)

This is not as bad as it seems since the EAR file simply contains the EJB JAR file and the WAR file. The EAR file is just a convenient wrapper to load your entire J2EE application into an Application Server or to a client machine at once.

We will quickly create all three deployment profiles, here are the steps:

  1. In the navigator, right-click the project node and choose New from the context menu.
  2. Select the Deployment Profiles category from the right side of the dialog.
  3. Select J2EE EJB Module (EJB JAR file) from the items list on the right side of the dialog.
  4. In the Save Deployment Profile dialog, click OK.
  5. In the J2EE EJB Module Deployment Profile Settings dialog, click OK.
  6. Repeat Steps 1 and 2.
  7. Select J2EE Web Module (WAR file) from the items list on the right side of the dialog.
  8. Repeat Steps 4 and 5.
  9. Repeat Steps 1 and 2
  10. Select J2EE Application (EAR file) from the items list on the right side of the dialog.
  11. In the Save Deployment Profile dialog, click OK.
  12. In the J2EE Application Deployment Profile Settings dialog, select the node Application Assembly.
  13. In the tree on the right side of the dialog, check both ejb1.deploy and webapp1.deploy.
  14. Click OK.
  15. Choose File | Save All.
  16. In the navigator, right-click the deployment profile application1.deploy, and choose Deploy to EAR from the context menu. This will create a file named application1.ear located in your projects directory.

Deploying the EJB jar File to WebSphere

The basic steps to deploy an EJB contained within an EAR file follow the pattern of deploy the archive, save the configuration, and then restart the application server. Here are step-by-step instructions for these activities.

  1. Launch the web based administration interface for WebSphere by launching your web browser on the URL http://localhost:9090/admin. This is the default port of the IBM HTTP Administration server which contains the web based administration tool.
  2. Enter any user name in the text field. This user name is only used for tracking changes to the configuration files for auditing purposes. Click the Submit button.
  3. In the tree on the left hand side of the web browser, expand the Nodes node in the tree, and then expand the node for your machine name. (This should be the only item in the tree under the Nodes node)
  4. Under the node for your machine name, select the node Enterprise Applications, this will open the editor for your Enterprise Beans and Web Applications on the right side.
  5. On the right side, click the Install button. This will invoke the Application Installation Wizard that will be used to deploy your EAR file.
  6. Near the top of this page, you will see a text field labeled " Path" with a Browse button to the right. Click the Browse button and locate the EAR file application1.ear that was created as part of creating the deployment profiles.
  7. Click the Next button.
  8. In the only text field on the page titled Binding Enterprise Beans to JNDI Names, change the JNDI name from the original value of mypackage/EJSStatelessMySessionEJBHomeBean to MySessionEJB.
  9. Click the Next button.
  10. On the next page which is titled: Specifying Virtual Host names and Precompiled JSP option for Web Modules, leave the values at their default and click the Next button.
  11. On the next page that is titled: Confirm the following: just click Finish.
  12. Look at the console window which executed the startServerBasic batch file, you will see many lines of diagnostic information. When finished, it should end in something like " [02.02.25 13:43:17:185 PST] 21349531 SystemOut U 0 Errors, 0 Warnings, 0 Informational Messages"
  13. Now you must save the configuration of WebSphere, click the Save link at the top of the web browser.
  14. Now click the Save button to save your configuration to the original configuration file, and not a secondary copy.
  15. Before the EJB and JSP can be invoked WebSphere must be restarted. Open a command prompt and change directories to the bin directory under your WebSphere installation. By default, this will be C:\WebSphere\AppServer\bin.
  16. Execute the batch file stopServer.bat. This will stop WebSphere.
  17. Now start WebSphere again, following the same steps as before.

Now the JSP and EJB are ready to be executed.

Testing the EJB in WebSphere

The URL that the web browser uses will be the same as used in the step Testing the EJB locally with the embedded OC4J with the port number changed from 8988 to 80. The default URL is http://localhost/Workspace1-Project1-context-root/untitled1.jsp.

  1. Launch your web browser.
  2. In the address line, type http://localhost/Workspace1-Project1-context-root/untitled1.jsp and press Enter.
  3. Verify that "Hello World" is displayed in the web browser.

References