Java EE 7 SDK 

Samples Main Page

The Automatic Timer EJB Sample Application (Test Client)

This is the standalone Java client for a simple EJB module that demonstrates how to use the EJB automatic timer.

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.

AutomaticTimerJavaClient is a client that runs outside of a Java EE container. In this case, the client performs a global JNDI lookup since dependency injection is not available outside of a Java EE environment.

Standalone Java Client

public class AutomaticTimerJavaClient {
    public static void main(String args[]) {
        try {
            StatelessSession sless = (StatelessSession)
                                      ic.lookup("java:global/automatic-timer-ejb/StatelessSessionBean");
            System.out.println("Waiting for the timer to expire");
            Thread.sleep(7000);
            List<String> result = sless.getRecords();
            System.out.println("Got " + result.size() + " log records:");
            for (String s : result) {
                System.out.println(s);
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Building, Deploying, and Running the Java Client

Since this is the client of automatic-timer-server, so please first go to samples_install_dir/javaee7/ejb/automatic-timer/automatic-timer-server, and run the instructions described in section "Building, Deploying, and Running the Application" in the sample's document.

Following are the instructions for building and running the Java Client.

  1. Setup your build environment and Configure the application server with which the build system has to work by following the common build instructions.
  2. app_dir is the sample application base directory: samples_install_dir/javaee7/ejb/automatic-timer/automatic-timer-client.
  3. Change directory to app_dir.
  4. Make sure that the database has been started up and the project automatic-timer-server has been built and deployed.
  5. Build and Run the standalone client.

    mvn clean verify exec:java

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.