EJB Deployment   «Prev  Next»

Create Deployable [Jar File] - Exercise

Create Deployable Jar File - Exercise

Deployable jar file

Objective: Create a deployable application that contains the jar file for the Hello bean.

Exercise scoring


You will receive 2 points for this exercise. The exercise is auto-scored; when you have completed the exercise, click the "OK, I'm Done" button to receive full credit.

Background/overview


You will be creating a deployable application that contains the jar file for the Hello bean. Notice that you deploy the bean without access to the source code, as I only provide you with the class files for this exercise. The jar file that you will create is the deployable unit for the Hello bean and contains all classes and information that is required.
If you are working on Windows, start an MS-DOS window. If you are working on UNIX, start a shell running in a window. Much of the work you do in exercises in this course will be done from the command line.
The Hello bean, for which you are creating the jar file, is a very simple session bean. It has the following interface:
String sayHello() throws HelloException
String sayHello(String s) 

The bean stores a name internally. When the client invokes sayHello() it will return a String containing "Hello name" where name is the name it has stored. If no name has been set, the String will throw a HelloException.
sayHello(String s) sets the internal name to the value of s and then returns "Hello name" where name will have the value set from String s.
Because the provided client initially invokes sayHello() without an argument, the first invocation throws a HelloException which is caught and displayed. The next invocation invokes sayHello("mickey") and sets the name before returning and displaying "Hello mickey".

Download files

Download the compressed jv309_project from the course repository.
file. Make sure that you choose either the UNIX or Windows version as appropriate.
Extracting the files will place them in the appropriate directories. Make sure you have a copy of the files. Do not use the originals.
The hello directory will include the following files:
Hello.class
HelloHome.class
HelloBean.class
HelloException.class
HelloClient.class
HelloClient.java
compileClient.bat
compileEJB.bat
runClient.bat

In all the examples in this course there are a number of script files to make your life easy. These will be .bat files on Windows or .sh files for Unix. The files are as follows:
compileEJB.bat/sh Compiles all the files required for the EJB
compileClient.bat/sh Compiles all the files required by the client.
runClient.bat/sh Runs the client once the EJB has been deployed.

Please use batch files with these names in all of the exercises that follow.

Instructions


Create the deployable jar file by completing the following steps:
  1. Make the hello directory current.
  2. Start the deploytool as follows: deploytool
  3. Using the deploytool, repeat the steps that were illustrated in the simulation. This will create the HelloEJB.jar file. The information for the Hello bean is as follows:
    Bean remote class: Hello.class
    Bean home class: HelloHome.class
    Bean class: HelloBean.class
    Additional classes: NSFException.class
    Display name: Hello
    Bean type: Session bean
    Management: Stateful Session
    The steps are repeated here:
    1. Choose "New Application..." from the File menu.
    2. In the combo box enter HelloApp for the application name and HelloApp.ear for the file that the application will stored in, then click the Submit button.
    3. Choose New Enterprise Bean... from the File menu. When the first window is displayed, click the Next button.
    4. Change the Display Name field to HelloEJB. In the contents box click on the Add button.
      This will take you to the Add Contents fo Jar Window so you can add the files required to the jar file.
    5. Select the files Hello.class, HelloBean.class, HelloHome.class, and HelloException.class from the file selector window and then click the Add button.
      The selected files will be shown in the lower window. Click the OK button.
    6. In the New Enterprise Bean Wizard window, the Contents text box shows the class files that you added. Click the Next button to continue
    7. Set the Classname of the bean to HelloBean, the home interface to HelloHome, and the remote interface to Hello.
      Set the Display name to Hello. Confirm that the bean type is Session and the state is Stateful. Click the Next button.
    8. Click the Next button five (5) times and the XML file will be displayed in the Review Settings window. Look at the XML file to see how it is constructed. When complete, click the Finish button.
    9. If you are not in the directory where the Hello files that you downloaded from the resources page were placed, then change to the correct directory using the Browse button.
    10. In the main Application Deployment Tool window, verify that the HelloApp application is displayed in the Local Applications panel. Open up the tree by clicking on the key. Click on each element in the tree and review the tabbed boxes and their contents in the Inspecting panel of the deployment tool.
    11. When you have finished, verify the existence of the .ear file in the directory.
  4. In the File menu click the Save... button to save the application.

Hints

Make sure that all the installation and configuration work was completed prior to performing these steps. If you did not, then things may not work correctly here.
You can verify that things were built correctly by saving the application (select Save from the File menu) and shutting down the deploytool. Then restart the deploy tool and open the HelloApp application. The deploytool should find and load the application and display its components in the Locals Applications panel and the details will be shown in the Inspecting panel. Try clicking on the various components and inspecting their contents. Remember that clicking on the key icon in the applications tree in the Local Applications panel opens up the branch.
To restart the whole process, simply select Close from the File menu and start again.
The server must be started and running (j2ee -verbose) before you start the deploytool. Make sure that you see the message "J2EE server startup complete" before starting the deploytool.
If you click any buttons by mistake that change the steps, exit the EJB Wizard and start again. Later, when you are more familiar with the tool, you will be able to back up and fix the problem easily.
Don't forget to add the HelloException.class to jar file.

Submitting your exercise

Click the Submit button to receive credit for this exercise and to continue on to the next lesson.