EJB module called ejb-embedded.jar is located
in the JVM classpath.
Standalone Java Client
public class TestClient {
private
static String appName;
public
static void main(String[] s) throws Exception {
TestClient t = new TestClient();
t.test();
}
private
void test() throws Exception {
EJBContainer c = null;
try {
c = EJBContainer.createEJBContainer();
Context ic = c.getContext();
System.out.println("Looking up EJB...");
SimpleEjb ejb = (SimpleEjb) ic.lookup("java:global/ejb-embedded/SimpleEjb");
System.out.println("Invoking EJB...");
System.out.println("Inserting entities...");
ejb.insert(5);
System.out.println("JPA count returned: " + ejb.verify());
System.out.println("Done calling EJB");
} finally {
if (c != null) {
System.out.println("Closing container ...");
c.close();
System.out.println("Done Closing container");
}
}
System.out.println("..........FINISHED Embedded test");
}
}
Building, Deploying, and Running the Java Client
Following are the instructions for building, deploying, and running
the Java Client.
- Setup your build environment and Configure the application
server with which the build system has to work by following the
common build instructions.
test_dir
is the sample application test
directory: samples_install_dir/javaee6/ejb/ejb-embedded/ejb-embedded-client
Change directory to test_dir.
- Make sure the JavaDB database is started. If not, refer to common build
instructions.
- Build, and Run the test using the target runtest
app_dir>
ant
runtest
- The runtest target depends on ejb-embedded.jar so make
sure
that the ejb code is built prior to running this target.
- In build.xml, the property 'classpath' is redefined to have
only the ejb and the client classes on which this test code depends, and the special
glassfish-embedded-static-shell.jar
that is located in the application
server's lib/embedded
directory. The property
'runjavaclient.class.name' points to the Java Client class name which
is invoked as a result of running ant runtest.
- Use the target clean to remove the temporary directories like
build and dist.
app_dir> ant
clean
Troubleshooting
If you have problems when running the application, refer to
troubleshooting document.
Copyright © 1997-2010 Oracle and/or its affiliates. All rights reserved.