Java Reference
In-Depth Information
text.lookup() to dynamically look up the resource you need. If your dynamic beha-
vior occurs in a non-container-managed resource, such as a utility class, you'll need to use
the InitialContext .
5.2.11. Application client containers
So far you've been learning about EJB and resource injection for applications that are de-
ployed inside an EE server and run inside the EE server as well. But what about SE applic-
ations that run outside the EE server that need to access the EJBs and other resources the
server manages? This is where the application client container (ACC) comes in.
The ACC is a hidden gem in the EE world. It's a mini Java EE container that can be run
from the command line. Think of it as a souped-up Java Virtual Machine (JVM) with some
Java EE juice added. You can run any Java SE client such as a Swing application inside the
ACC as if you were using a regular JVM. The beauty of it is that the ACC will recognize
and process most Java EE annotations such as the @EJB annotation. Among other things,
the ACC can look up and inject EJBs on remote servers, communicate with remote EJBs
using RMI, provide authentication, perform authorization, publish and subscribe to JMS
resources, and so forth. The ACC really shines if you need to use EJBs in an SE application
or would like to inject real resources into your POJO during unit testing.
Any Java class with a main method can be run inside the ACC. Typically, you package your
application as a JAR and define the MainClass in META-INF/MANIFEST . Option-
ally, the JAR may contain a deployment descriptor ( META-INF/application-cli-
ent.xml ) and a jndi.properties file that contains the environment properties for
connecting to a remote EJB container. As a quick example, if the ActionBazaar EE applic-
ation had a remote bid service EJB, an SE application would simply use a static property to
inject it, as follows:
@EJB
private static BidService remoteBidService;
public class BidServiceClient {
public static void main(String[] args) {
System.out.println("result = " + remoteBidService.addBid(bid));
}
Once you've created your SE application, the process of running it in the ACC is EE serv-
er-specific. Let's take a quick look at how to do this with GlassFish. Assume you pack-
Search WWH ::




Custom Search