Show TOC

Background documentationCreating and Implementing the Application Client Locate this document in the navigation structure

Prerequisites

The   Windows   Open Perspective   Other   Java EE   perspective is opened.

Procedure

1. Create the Application Client Project
  1. Choose   File   New   Project  from the main menu.

  2. Expand Java EE folder and choose Application Client Project. Choose Next.

    This graphic is explained in the accompanying text.

  3. Enter CalculatorServiceClient in the Project name field. This is the name of the Application Client Project.

  4. Leave the Default Configuration for SAP Libraries in the Configurations field. The default configurations include the Application Client module 5.0 and Java 6.0 project facets.

  5. To assign the Application Client Project to an Enterprise Application Project, choose Add project to an EAR and select CalculatorServiceEAR in the EAR Project Name field.

    This graphic is explained in the accompanying text.

  6. Choose Finish to create the Application Client Project.

2. Implement the Application Client
  1. Copy the Java source below.

  2. Expand the project CalculatorServiceClient.

  3. From the context menu of appClientModule folder, choose Paste.

    Syntax Syntax

    1. package com.sap.blogs.appclient.calculator.client;
      
      import com.sap.blogs.appclient.calculator.ejb.CalculatorRemote;
      import javax.ejb.EJB;
      
      public class CalculatorClient {
      	@EJB
      	private static CalculatorRemote calculator;
      
      	/**
      	 * Creates a new instance of Starter
      	 */
      	public CalculatorClient() {
      	}
      
      	/**
      	 * @param args
      	 *            the command line arguments
      	 */
      	public static void main(String[] args) {
      		System.out.println("Welcome to calculator service!");
      		System.out.println();
      		System.out.print("Adding (4+6): ");
      		long result = calculator.add(4, 6);
      		System.out.println(result);
      	}
      }
      
    End of the code.

    Note Note

    A peculiarity of all Application Client applications is that they have to specify their main class in the archive's manifest file. Open META-INF/MANIFEST.MF and append:

    Main-Class: com.sap.blogs.appclient.calculator.client.CalculatorClient

    End of the note.
3. Configure the Project References

Since your Application Client project uses resources from the CalculatorServiceEJB project, you have to set these references:

  1. Select CalculatorServiceClient in the Project Explorer.

  2. From the context menu, choose Properties.

  3. On the Properties for CalculatorServiceClient screen choose   Java Build Path   Projects  .

  4. Choose Add.

  5. Select CalculatorServiceEJB.

    This graphic is explained in the accompanying text.

  6. Choose OK.

  7. Choose Project References.

  8. On the Setting Java Build Path screen that pops up, choose Apply.

  9. Select the CalculatorServiceEAR and CalculatorServiceEJB projects.

  10. Choose OK.