Home arrow Java & J2EE arrow Page 12 - Introduction to Enterprise JavaBeans

Verifying the Case Study Application - Java

This chapter looks at one of the principal types of component in the Java 2 Platform, Enterprise Edition (J2EE) — Enterprise JavaBeans (EJBs). See how EJBs are applied and how they are deployed. (This is chapter 4 from Sams Publishers, author Martin Bond, et. al., Teach Yourself J2EE in 21 Days, second edition, ISBN: 0-672-32558-6).

  1. Introduction to Enterprise JavaBeans
  2. Types of EJB and Common Uses of EJBs
  3. What's in an EJB?
  4. The Home Interface
  5. Implementing the Home Interface
  6. Verifying an EJB
  7. The EJB-JAR File
  8. How Do I Deploy an EJB?
  9. Disposing of the EJB
  10. Using the J2EE Reference Implementation
  11. Examining the Case Study Application
  12. Verifying the Case Study Application
  13. Managing J2EE RI Applications
  14. Troubleshooting the Case Study Application
By: Martin Bond
Rating: starstarstarstarstar / 41
June 21, 2004

print this article



The J2EE RI comes with a verifier utility that you can use to validate the contents of an EAR file. The verifier can be run from the command line or it can be invoked from the Tools, Verify J2EE Compliance... menu option from within deploytool.

Note - The authors used J2EE SDK 1.4 released in November 2003 for the development of the code used in this book. Unfortunately they encountered problems when running the verifier from within deploytool. Specifically running the verifier against this simple example incorrectly reported a problem with a missing JNDI name for the jdbc/Agency resource reference. Running the command line verifier against the same EAR file did not report a problem. You are urged to double check any verification problems reported from deploytool by using the command line verifier utility. For the example case study you can do this manually using the command

verifier j2ee-ri/agency.ear

from within the Day04/exercise directory. Alternatively use the supplied asant build files (see section "Case Study asant Build Files") and enter

asant verify-j2ee-ri

Caution - Micosoft Windows users should be aware that there is a standard Windows 2000/XP utility called verifier. If you have not put the %J2EE_HOME%\bin directory at the start of your PATH environment variable you will have to use the command


to run the J2EE SDK verifier. The supplied asant build files for the case study use the fully qualified file name and therefore do not require the PATH to be modified.

You are advised to run verifier on all new EAR files or when changes have been made to any of the files composing an EJB. To illustrate the use of the verifier, Figure 4.10 shows the errors produced by a simple mistake in coding the AgencyBean.java class; in this case the ejbCreate() method was mistakenly defined as create().


Figure 4.10
verifer errors from a missing ejbCreate() method in AgencyBean.java.

Running the verifier from within deploytool produces a list of failed tests or a brief "There were no failed tests" message. Selecting each failed test in turn will supply further information about the test. In Figure 4.10 the message indicates the following:

 [agency.AgencyBean] does not properly declare at least one ejbCreate() method

A simple mistake can cause the failure of many tests, so do not be alarmed if you see a large number of test failures.

Caution - The verifier tool works from the on-disk EAR file and not from the in-memory copy created by deploytool. Make sure you save your application using the File, Save menu option before running verifier.

After you have written, packaged up your application, and verified the application contents, you are ready to deploy.

Deploying the Case Study Application

You can deploy the server-side components of the agency application using deploytool. To deploy the agency application, select the agency application item (indicated by a blue diamond under the Applications folder in the explorer area in the left-hand panel), and select the Tools, Deploy... menu. This will display the initial deployment screen shown in Figure 4.11.


Figure 4.11
Deployment dialog for the Agency case study.

You will need to provide the administrative username and password (admin and password if you installed the J2EE SDK as described on Day 2). You should also check the Return Client Jar box on the dialogue to ensure your Application Client Jar file is downloaded from the J2EE server. Accept the default location for the client JAR file (this will be the same directory as the EAR file).

Click on OK to proceed with deploying your application and then click Close on the popup window when the deployment completes.

Note - If your J2EE component has already been deployed, the existing version will be undeployed, and then the new version will be deployed. When redeploying an application the J2EE RI will not return a new client JAR file even if asked it to do so. You will either have to do this manually or explicitly undeploy and redeploy your application as described in the section "Managing J2EE RI Applications."

This is the point at which things might go wrong. If you are using the software from the Web site, you should have no trouble, but if you are developing your own example then you might come across problems at this stage. The "Troubleshooting Deployment" section, later on, discusses problems that might occur at deployment. If something does go wrong, study the information in the deployment progress window and also look at the J2EE console window for additional, more detailed information.

Running the Application Client

After you have successfully deployed the server-side components of the application under the J2EE RI, you can run the simple application client to test the application.

To run an application client you must have obtained the client-side JAR file from the deployed application. You did this when you deployed the application by checking the Return Client Jar... box on the deployment popup window. You can also obtain the client JAR file using either deploytool, the Web-based Admin Console, or the command line asadmin utility as described in the following section "Managing J2EE RI Applications."

The client JAR file contains all the client and EJB class files as well as the RMI stub files required to run the application client.

You run a J2EE RI application client using the appclient command (from the J2EE SDK bin directory). The appclient requires the name of the client JAR as its single –client parameter. Assuming you have followed the deployment process described in the previous section, your returned client JAR file will be in the Day02/exercise/ j2ee-ri directory and called agencyClient.jar.

You can run your deployed client as follows (your command entry is shown in bold):

appclient -client j2ee-ri/agencyClient.jar
Welcome to: J2EE in 21 Days Job Agency
Customer list: J2EE in 21 Days Job Agency


The client JAR file is always named after the application by appending Client.jar to the name of the application.

Congratulations, you have just deployed and run your first J2EE application. If the client fails to run, then look at the errors on the console window or in the domains/domain1/logs/server.log file in the J2EE SDK home directory for more information.

If you want to examine the simple Web Application you deployed with the EJB, then browse to the URL http://localhost:8000/webagency. You will look at Web Applications in detail on Days 12, 13, and 14.

This chapter is from Teach Yourself J2EE in 21 Days, second edition, by Martin Bond et. al. (Sams, 2004, ISBN: 0-672-32558-6). Check it out at your favorite bookstore today. Buy this book now.

>>> More Java & J2EE Articles          >>> More By Martin Bond

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: