Java EE 7 SDK 

Samples Main Page

The Stateless Bean EJB Sample Application (Test Client)

This sample is a Java client that uses a EJB stateless session bean with a remote business interface. The Java client runs outside of a Java EE container and performs a global JNDI lookup, since dependency injection is not available outside of a Java EE component.

Description

This sample application consists of two parts: an EJB module and a test client (this project). The rest of this document describes the test client.

Standalone Java Client

public class StatelessJavaClient {

    public static void main(String args[]) {
        try {
            InitialContext ic = new InitialContext();
            StatelessSession sless = (StatelessSession) ic.lookup("javaee_samples.hello.stateless.StatelessSession");
            System.out.println("StatelessSession bean says : " + sless.hello());
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
} 
				

Key Features

The test client demonstrates how to perform a JNDI lookup for an EJB and how to use its business methods.

Building, Deploying, and Running the Java Client

Perform the following steps to build, deploy, and run the Java Client:

  1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
  2. This project depends on hello-stateless-ejb-bean. Follow the instruction for deploying hello-stateless-ejb-bean first. Ensure that the EJB bean has been built and deployed. Ensure also that the GlassFish server is running.
  3. app_dir is the sample application base directory: samples_install_dir/javaee7/ejb/hello-stateless-ejb/hello-stateless-ejb-client.
  4. Change directory to app_dir.
  5. Build, deploy, and run the sample application using the run outcome.

    mvn clean verify exec:java

  6. Use the clean outcome to undeploy the sample application and to remove the temporary directories such as target.

    mvn clean

Troubleshooting

If you have problems when running the application, refer to the troubleshooting document.



Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.