| Java EE 7 SDK |
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.
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.
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();
}
}
}
The test client demonstrates how to perform a JNDI lookup for an EJB and how to use its business methods.
Perform the following steps to build, deploy, and run the Java Client:
app_dir is the sample application base directory: samples_install_dir/javaee7/ejb/hello-stateless-ejb/hello-stateless-ejb-client.app_dir.run outcome.
mvn clean verify exec:java
clean outcome to undeploy the sample application and to remove the temporary directories such as target.
mvn clean
If you have problems when running the application, refer to the troubleshooting document.
Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.