Java EE Application client container
Categories:
Understanding the Java EE Application Client Container (ACC)

Explore the Java EE Application Client Container (ACC), its role in running standalone Java EE clients, and how it simplifies client-side development for enterprise applications.
The Java EE Application Client Container (ACC) is a specialized runtime environment that allows standalone Java applications to access Java EE services. Unlike web or EJB clients that run within a web server or EJB container, ACC clients execute as regular Java applications but benefit from the full suite of Java EE features, such as JNDI, EJB access, JMS, and transaction management. This article delves into the architecture, benefits, and practical usage of the ACC, providing a comprehensive guide for developers looking to build robust enterprise clients.
What is the Application Client Container (ACC)?
The ACC is a lightweight container that provides a client-side view of the Java EE platform. It bridges the gap between a simple standalone Java application and the complex services offered by a full-fledged Java EE application server. Essentially, it injects Java EE capabilities into a standard Java Virtual Machine (JVM), allowing client applications to look up and invoke remote enterprise beans, send and receive JMS messages, and participate in distributed transactions, all while running outside the application server's main process.
flowchart TD A[Standalone Java Client] --> B{ACC Runtime} B --> C[JNDI Lookup] B --> D[EJB Remote Invocation] B --> E[JMS Messaging] B --> F[Transaction Management] C --> G(Application Server) D --> G E --> G F --> G G --> H[Enterprise Services]
Interaction of a Standalone Java Client with Java EE Services via ACC
Key Features and Benefits of ACC
The ACC offers several advantages for developing enterprise client applications:
- Simplified Access to Java EE Services: Clients can directly use Java EE APIs (e.g., EJB, JMS, JNDI) without needing to implement complex communication protocols or security mechanisms manually.
- Managed Environment: The ACC provides a managed environment for the client, handling resource injection, security context propagation, and transaction demarcation, similar to how an EJB container manages EJBs.
- Deployment Flexibility: Application clients can be deployed and run on various client machines, including desktops, without requiring a full application server installation on each client.
- Security Integration: It integrates with the application server's security infrastructure, allowing clients to authenticate and authorize against enterprise resources.
- Resource Management: The container manages client-side resources, such as database connections or JMS connections, often through connection pooling, improving performance and reliability.
- Offline Capabilities: While primarily designed for online interaction, some ACC implementations might support limited offline capabilities or caching for improved user experience.
Developing and Deploying an ACC Client
Developing an ACC client involves writing standard Java code that leverages Java EE APIs. The key difference lies in how the client is packaged and launched. Typically, the client application, along with its dependencies and a client-specific deployment descriptor (e.g., application-client.xml
), is packaged into a JAR file. This JAR is then deployed to the application server, which generates a client-specific JAR (often called a 'thin client' or 'client stub' JAR) that contains the necessary runtime libraries and stubs for remote invocation.
To run the client, you execute a special launcher provided by the application server, which sets up the ACC environment and invokes your client's main
method. This launcher ensures that the client has access to the necessary JNDI context, security credentials, and other Java EE services.
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
public class MyEJBClient {
public static void main(String[] args) {
try {
// The ACC typically provides the initial context automatically
// For standalone testing, you might configure it explicitly
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.enterprise.naming");
props.setProperty(Context.PROVIDER_URL, "iiop://localhost:3700"); // Adjust for your server
Context initialContext = new InitialContext(props);
// Look up the remote EJB interface
// The JNDI name depends on your EJB deployment
MyRemoteEJB myEJB = (MyRemoteEJB) initialContext.lookup("java:global/MyApp/MyEJB!com.example.MyRemoteEJB");
// Invoke a method on the EJB
String result = myEJB.sayHello("ACC User");
System.out.println("EJB Response: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Example Java EE Application Client accessing a remote EJB
1. Develop the EJB and Client Interface
Create your Enterprise JavaBean (EJB) with a remote interface. The client will interact with this remote interface.
2. Write the Application Client
Develop your standalone Java application that uses JNDI to look up the remote EJB and invoke its methods. Ensure your client code uses the remote interface.
3. Package the Client
Package your client application into a JAR file. Include any necessary client-side deployment descriptors (e.g., application-client.xml
if required by your server).
4. Deploy to Application Server
Deploy the client JAR (or the entire EAR containing the client and EJB) to your Java EE application server (e.g., GlassFish, WildFly, WebSphere). The server will typically generate a 'thin client' JAR.
5. Obtain Client Stubs
Download or locate the generated client stub JAR from your application server. This JAR contains the necessary classes for the client to communicate with the server.
6. Run the Client
Execute the client using the application server's provided client launcher script or command, ensuring the client stub JAR is on the classpath. This launcher initializes the ACC environment.