Java Reference
In-Depth Information
Click here to view code image
Properties props = new Properties();
props.setProperty(EJBContainer.MODULES, "mySessionBean");
EJBContainer ec = EJBContainer.createEJBContainer(props);
To specify enterprise bean modules outside the virtual machine classpath, set EJBCon-
tainer.MODULES to a java.io.File object or an array of File objects. Each
File object refers to an EJB JAR file, or a directory containing an expanded EJB JAR.
Click here to view code image
Properties props = new Properties();
File ejbJarFile = new File(...);
props.setProperty(EJBContainer.MODULES, ejbJarFile);
EJBContainer ec = EJBContainer.createEJBContainer(props);
Looking Up Session Bean References
To look up session bean references in an application using the embedded container, use an
instance of EJBContainer to retrieve a javax.naming.Context object. Call the
EJBContainer.getContext method to retrieve the Context object.
Click here to view code image
EJBContainer ec = EJBContainer.createEJBContainer();
Context ctx = ec.getContext();
References to session beans can then be obtained using the portable JNDI syntax detailed
in “Portable JNDI Syntax” in The Java EE 6 Tutorial: Basic Concepts . For example, to
obtain a reference to MySessionBean , a local session bean with a no-interface view,
use the following code:
Click here to view code image
MySessionBean msb = (MySessionBean)
ctx.lookup("java:global/mySessionBean/MySessionBean");
Shutting Down the Enterprise Bean Container
From the client, call the close method of the instance of EJBContainer to shut down
the embedded container:
Search WWH ::




Custom Search