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

Managing J2EE RI Applications - 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



You can manage J2EE RI applications using any of the following interfaces:

  • deploytool

  • The asadmin command line utility

  • The Admin Console web application (http://localhost:4848/asadmin/)

Using deploytool you can obtain a list of deployed objects by selecting the localhost:4848 entry under Servers in the left pane and a list of deployed components will be displayed, as shown in Figure 4.12.


Figure 4.12
Managing J2EE Deployed Objects with deploytool.

You can start, stop and undeploy an object using the appropriate buttons on this dialog.

Should you need to retrieve a client JAR file from a deployed application you can do this by selecting your application, clicking on the Client Jar... button and specifying a directory location on the popup dialogue window.

If you prefer to work from the command line, then you can use the asadmin utility. To deploy an application you use the asadmin deploy command. To deploy the example EAR file you have been viewing use the command

asadmin deploy --user admin --force j2ee-ri/agency.ear

You need to specify the name of your administrative user and the EAR filename; the --force option forces a redeployment if the application has already been deployed. You will be prompted for the administrative password unless you have stored this password in a configuration file, or as an environment variable, as described on Day 2 under the installation instructions for the J2EE SDK.

If you want to return the client JAR file when deploying an application use a command such as:

asadmin deploy --user admin --force --retrieve j2ee-ri j2ee-ri/agency.ear

The --retrieve option requires the name of the directory for the client JAR file; the client JAR filename is derived from the application name as described previously.

You can retrieve the client JAR file for a previously deployed application using the get-client-stubs command to asadmin as follows:

asadmin get-client-stubs --user admin --appname agency j2ee-ri

This command requires the application name (--appname option) and the target directory for the client JAR file.

As discussed on Day 2 asadmin will provide useful help messages when an invalid command is entered. And, you can always use the --help option to get more information. For example:

asadmin -help
asadmin deploy -help
admin get-client-subs --help

Finally, you can administer deployed applications using the J2EE RI Admin Console at http://localhost:4848/asadmin/. Select the Applications, Enterprise Applications option in the left pane to deploy and undeploy applications as shown in Figure 4.13.

You can only stop, start, deploy and undeploy applications using the Admin Console interface; you cannot return client JAR files.


Figure 4.13
Using the J2EE RI Admin Console to Manage J2EE Components.

Case Study asant Build Files

As an alternative to using deploytool to build and deploy J2EE components, you can use Apache Ant (sometimes called Jakarta Ant) to assemble the EAR or WAR files from the constituent components. Ant is a Java-based, open source, automated build tool that is quickly becoming the de facto standard build tool for Java programmers. A version of Apache Ant, called asant, is included with the J2EE SDK and example asant build files are supplied with the J2EE 1.4 Tutorial examples. A discussion on writing the Ant build files required to assemble a J2EE archive is outside the scope of this book, but the online Ant documentation at http://ant.apache.org/manual/index.html gives a good introduction to writing build files. Alternatively you could check out the book Extreme Programming with Ant from SAMS Publishing.

On the accompanying Web site, asant build files have been provided to compile and package the EAR and WAR files used throughout this book. As described in Day 2, each working directory contains a build.xml file that defines the asant build targets appropriate for the directory.

The build.xml file in the Day04/exercise directory will build, deploy, and run the simple client example. In order to help you use asant with the case study, each build.xml file contains a help build target that will tell you which targets you can use for each directory, this is also the default asant target. Run the following command from the Day04/exercise directory to see what targets are available:


To remove all the temporary files and then compile and build the case study from scratch, use the command

asant clean build

The generated agency.ear file is stored in the build subdirectory and is kept separate from the supplied agency.ear file in the j2ee-ri directory. The various deployment descriptors used to build the EAR file are kept in the dd/agency subdirectory.

You can verify the built application using the command

asant verify

The verification results from this command are stored in the file build/agency.ear.txt.

To deploy the case study from the build directory, use the command

asant deploy

This will return the client JAR as build/agencyClient.jar. To run the simple client example, use the command

asant run

You should see the following output:

   [echo] (build) appclient.bat -client agencyClient.jar -name SimpleClient
   [exec] Welcome to: J2EE in 21 Days Job Agency
   [exec] Customer list: J2EE in 21 Days Job Agency
   [exec] abraham
   [exec] alfred
   [exec] george
   [exec] winston

   [exec] Done

To undeploy the agency example use

asant undeploy

If you want to use deploytool to build the EAR file but work at the command line to verify, deploy and run the examples, then you can use the following commands.

Verify the deploytool maintained agency.ear file in the j2ee-ri sub-directory with

asant verify-j2ee-ri

Deploy and return the j2ee-ri/agencyClient.jar file with

asant deploy-j2ee-ri

Run the application client (in the j2ee-ri sub-directory) using

asant run-j2ee-ri

To undeploy the agency example you still use

asant undeploy

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: