Sun GlassFish Enterprise Server 2.1 Developer's Guide

ProcedureTo Access an EJB Component From an Application Client

  1. In your client code, reference the EJB component by using an @EJB annotation or by looking up the JNDI name as defined in the ejb-jar.xml file.

    For more information about annotations in application clients, see section 9.4 of the Java EE 5 Specification.

    For more information about naming and lookups, see Accessing the Naming Context.

    If load balancing is enabled as in Step 7 and the EJB components being accessed are in a different cluster, the endpoint list must be included in the lookup, as follows:

    corbaname:host1:port1,host2:port2,.../NameService#ejb/jndi-name
    
  2. Define the @EJB annotations or the ejb-ref elements in the application-client.xml file. Define the corresponding ejb-ref elements in the sun-application-client.xml file.

    For more information on the application-client.xml file, see the Java EE 5 Specification, Section EE.9.7, “Java EE Application Client XML Schema.”

    For more information on the sun-application-client.xml file, see The sun-application-client.xml file in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide. For a general explanation of how to map JNDI names using reference elements, see Mapping References.

  3. Deploy the application client and EJB component together in an application.

    For more information on deployment, see the Sun GlassFish Enterprise Server 2.1 Application Deployment Guide. To get the client JAR file, use the --retrieve option of the asadmin deploy command.

    To retrieve the stubs and ties whether or not you requested their generation during deployment, use the asadmin get-client-stubs command. For details, see the Sun GlassFish Enterprise Server 2.1 Reference Manual.

  4. Ensure that the client JAR file includes the following files:

    • A Java class to access the bean.

    • application-client.xml - (optional) Java EE application client deployment descriptor. For information on the application-client.xml file, see the Java EE 5 Specification, Section EE.9.7, “Java EE Application Client XML Schema.”

    • sun-application-client.xml - (optional) Enterprise Server specific client deployment descriptor. For information on the sun-application-client.xml file, see The sun-application-client.xml file in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

    • The MANIFEST.MF file. This file contains a reference to the main class, which states the complete package prefix and class name of the Java client.

  5. Prepare the client machine. This step is not needed for Java Web Start.

    If you are using the appclient script, either package the application client to run on a remote client system using the package-appclient script, or copy the following JAR files to the client machine manually and include them in the classpath on the client side:

    • appserv-rt.jar - available at as-install/lib

    • javaee.jar - available at as-install/lib

    • The client JAR file

    For more information, see Using the package-appclient Script.

  6. To access EJB components that are residing in a remote system, make the following changes to the sun-acc.xml file. This step is not needed for Java Web Start.

    This information can be obtained from the domain.xml file on the remote system. For more information on domain.xml file, see the Sun GlassFish Enterprise Server 2.1 Administration Reference.

  7. To set up load balancing and failover of remote EJB references, define at least two target-server elements in the sun-acc.xml file. This step is not needed for Java Web Start.


    Note –

    Some topics in the documentation pertain to features that are available only in domains that are configured to support clusters. Examples of domains that support clusters are domains that are created with the cluster profile or the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server 2.1 Administration Guide.


    If the Enterprise Server instance on which the application client is deployed participates in a cluster, the ACC finds all currently active IIOP endpoints in the cluster automatically. However, a client should have at least two endpoints specified for bootstrapping purposes, in case one of the endpoints has failed.

    The target-server elements specify one or more IIOP endpoints used for load balancing. The address attribute is an IPv4 address or host name, and the port attribute specifies the port number. See client-container in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

  8. Run the application client.

    See Using Java Web Start or Running an Application Client Using the appclient Script.