InfoCenter Home >
4: Developing applications >
4.7: Java Clients >
4.7.2: J2EE application client programming model >
4.7.2.2: Developing a J2EE application client

4.7.2.2: Developing a J2EE application client

From an application developer's point of view, creating a J2EE application client program involves these steps:

  1. Writing the client application program
  2. Assembling the application client (using the Application Assembly Tool)
  3. Assembling the Enterprise Archive (EAR) file
  4. Distributing the EAR file
  5. Configuring the application client resources
  6. Launching the application client


  1. Writing the client application program

      Write the J2EE application client program on any development machine. At this stage, you do not require access to WebSphere Application Server.

      A J2EE application client program is similar to a standard Java program in that it runs in its own Java virtual machine and is invoked at its main method. The J2EE application client program differs from a standard Java program because it uses the JNDI name space to access resources. In a standard Java program, the resource information is coded in the program.

      Storing the resource information separately from the client application program makes the client application program portable and more flexible.

      Using the javax.naming.InitialContext class, the client application program uses the lookup operation to access the JNDI name space. The InitialContext class provides the lookup method to locate resources. For more information on JNDI, see file, JNDI overview.

      The following example illustrates how a client application program uses the InitialContext class:

      import javax.naming.*
      
      public class myAppClient
      {
      public static void main(String argv[])
      {
      InitialContext ctx = new InitialContext();
      Object myObj = ctx.lookup("java:comp/env/ejb/HelloBean");
      HelloHome home =(HelloHome)javax.rmi.PortableRemoteObject.narrow(myObj, HelloHome.class);
      ...
      }
      }
      
      In this example, the program is looking up an Enterprise Java Bean called HelloBean. The HelloBean EJB reference is located in the client JNDI name space at java:comp/env/ejb/HelloBean. Since the actual Enterprise Java Bean is running on the server, the application client runtime returns a reference to HelloBean's home interface.

      If the client application program's lookup was for a Resource reference or an Environment entry, then lookup would return an instance of the configured type as defined by the client application's Deployment Descriptor. For example, if the program's lookup was a JDBC datasource, the lookup would return an instance of javax.sql.DataSource.

  2. Assembling the application client (using the Application Assembly Tool)

      The JNDI name space knows what to return on a lookup because of the information that is assembled by the Application Assembly Tool (AAT).

      Assemble the J2EE application client on any development machine that has the AAT installed.

      When you use the Application Assembly Tool to assemble your application client, you provide the application client runtime with the required information to initialize the execution environment for your client application program. Refer to the Application Assembly Tool description for implementation details.

      Here is a list of things to keep in mind when you configure resources used by your client application program:

      • When configuring Resource references and EJB references in the Application Assembly Tool, the General tab contains a required Name field. This field specifies where the application client runtime will bind the reference to the real object in the java:comp/env portion of the JNDI namespace. The application client runtime always binds these references relative to java:comp/env. So, for the programming example above, you would specify ejb/HelloBean in the Name field on the General tab of the Application Assembly Tool, which would require the program to perform a lookup of java:comp/env/ejb/HelloBean. If the Name field were set to myString, the resulting lookup would be java:comp/env/myString.
      • When configuring Resource references in the Application Assembly Tool, the Name field on the General tab is used for:
        • binding a reference of that object type into the JNDI name space.
        • retrieving client specific resource configuration information that was configured using the Application Client Resource Configuration Tool.

      • When configuring a Resource reference in the Application Assembly Tool, the value in the Name field on the General tab must match the value in the JNDI Name field on the General tab for the resource in the Application Client Resource Configuration Tool.
      • When configuring URL resources using the Client Resource Configuration Tool, the URL provider panel allows you to specify a protocol and a class that handles that protocol. If you want to use the default protocols, such as HTTP, you can leave those fields blank.
      • When configuring Resource references using the Application Assembly Tool, the General tab contains a field called Authorization. This field can be set to either Container or Application. If the field is set to Container, then the application client runtime will use authorization information configured in the Application Client Resource Configuration tool for the resource. If the field is set to Application, then the Application Client runtime expects the user application to provide authorization information for the resource. The application client runtime will ignore any authorization information configured with the Application Client Resource Configuration tool for that resource.

  3. Assembling the Enterprise Archive (EAR) file

      The application is contained in an Enterprise Archive or .ear file. The .ear file is composed of:
      • EJB, Application Client, and user-defined modules or .jar files
      • Web applications or .war files
      • Metadata describing the applications or application .xml files

      You must assemble the .ear file on the server machine.

  4. Distributing the EAR file

      The .ear file must be made accessible to those client machines that are configured to run this client.

      If all the machines in your environment share the same image and platform, run the Application Client Resource Configuration Tool (ACRCT) on one machine to configure the external resources, and then distribute the configured .ear file to the other machines.

      If your environment is set up with a variety of client installations and platforms, you must run the ACRCT for each unique configuration.

      The .ear files can either be distributed to the correct client machines, or made available on a network drive.

      See article Packaging and distributing Java clients for more information.

      Distributing the .ear files is the responsibility of the system and network administrator.

  5. Configuring the application client resources

      If local resources are defined for use by the client application, run the ACRCT on the local machine to reconfigure the .ear file. Use the ACRCT to change the configuration. The ACRCT is the Application Client Resource Configuration Tool described in the previous steps. For example, the .ear file may contain a a DB2 resource, which is configured as C:\DB2. If, however, the user has DB2 installed in directory, D:\Program Files\DB2, that user must use the ACRCT to create a local version of the .ear file.

  6. Launching the application client

      Using the fully assembled and configured .ear file, issue the launchClient command to launch the J2EE application client on the client machine.

      Note:  Learn more about the WebSphere J2EE client by running the client sample. You can install the client sample from the WebSphere Application Client CD. On a server machine, the J2EE client sample is part of the samples gallery. See the "Application Client" section of Samples.ear. This sample is called HelloEJB and is installed in the product_installation/WSsamples/Client subdirectory on the client machine.

Go to previous article: Resources referenced by a  J2EE application client Go to next article: Troubleshooting guide for the J2EE application client

 

 
Go to previous article: Resources referenced by a  J2EE application client Go to next article: Troubleshooting guide for the J2EE application client