In your client code, instantiate the InitialContext using the default (no argument) constructor:
InitialContext ctx = new InitialContext();
It is not necessary to explicitly instantiate a naming context that points to the CosNaming service.
In your client code, look up the home object by specifying the JNDI name of the home object as specified in the ejb-jar.xml file.
Object ref = ctx.lookup("java:comp/env/ejb-ref-name"); BeanAHome = (BeanAHome)PortableRemoteObject.narrow(ref,BeanAHome.class);
If load balancing is enabled as in Step 8 and the EJB components being accessed are in a different cluster, the endpoint list must be included in the lookup, as follows:
For more information about naming and lookups, see Accessing the Naming Context.
Define the ejb-ref elements in the application-client.xml file and the corresponding sun-application-client.xml file.
For more information on the sun-application-client.xml file, see The sun-application-client.xml file. For a general explanation of how to map JNDI names using reference elements, see Mapping References.
Deploy the application client and EJB component together in an application.
For more information on deployment, see Tools for Deployment. To get the client JAR file, use the --retrieve option.
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 Java System Application Server Enterprise Edition 8.1 2005Q2 Reference Manual.
Ensure that the client JAR file includes the following files:
a Java class to access the bean
application-client.xml - J2EE 1.4 application client deployment descriptor.
sun-application-client.xml - Application Server specific client deployment descriptor. For information on the sun-application-client.xml file, see The sun-application-client.xml file.
The MANIFEST.MF file. This file contains the main class, which states the complete package prefix and class name of the Java client.
You can package the application client using the package-appclient script. This is optional. See Packaging an Application Client Using the ACC.
Copy the following JAR files to the client machine and include them in the classpath on the client side:
appserv-rt.jar - available at install-dir/lib
j2ee.jar - available at install-dir/lib
The client JAR file
Define the target-server element’s address attribute to reference the remote server machine.
Define the target-server element’s port attribute to reference the ORB port on the remote server.
This information can be obtained from the domain.xml file on the remote system. For more information on domain.xml file, see the Sun Java System Application Server Enterprise Edition 8.1 2005Q2 Administration Reference.
To set up load balancing and failover of remote EJB references, define the following property as a property subelement of the client-container element in the sun-acc.xml file:
The endpoints property specifies a comma-separated list of one or more IIOP endpoints used for load balancing. An IIOP endpoint is in the form host:port, where the host is an IPv4 address or host name, and the port specifies the port number.
If the endpoints list is changed dynamically in the code, the new list is used only if a new InitialContext is created.
Run the application client. See Running an Application Client Using the ACC.
The following sample application demonstrates client load balancing and failover: