EJB Deployment   «Prev  Next»

Lesson 8

EJB Deployment Conclusion

Here are the three primary tasks for deploying an enterprise bean in Jakarta EE 10, written clearly and independently
A deeper breakdown of the "three primary tasks" for deploying an enterprise bean in Jakarta EE 10, with each step expanded.
βœ… 1. Define the Enterprise Bean
Use Jakarta EE annotations such as `@Stateless`, `@Stateful`, or `@MessageDriven` to define the bean type. Client views can be specified using `@Local` or `@Remote` interfaces.
πŸ” Configuration Details Using Annotations or `ejb-jar.xml`:
βœ… Common Annotation-Based Configurations:
Transaction Management:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void processOrder() { ... }

Security Roles:
@RolesAllowed("Manager")
public void approveReport() { ... }

Resource Injection:
@Resource
private DataSource dataSource;

Timer Services:
@Schedule(hour="*", minute="0", second="0", persistent=false)
public void hourlyTask() { ... }

βœ… Optional `ejb-jar.xml` Use Cases:
Use the deployment descriptor when:
  • You want to override annotations for different environments.
  • You are applying security role mappings, resource references, or interceptor bindings that are externalized from the code.
  • You are managing vendor-specific configurations not expressible in annotations.


Example snippet:
<session>
    <ejb-name>OrderProcessor</ejb-name>
    <ejb-class>com.example.ejb.OrderProcessor</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    <security-role-ref>
        <role-name>Manager</role-name>
    </security-role-ref>
</session>

βœ… 2. Package the Bean into a JAR File (with Maven)
Use Apache Maven to bundle compiled `.class` files and resources into a JAR. Here is a minimal `pom.xml` for an EJB module:
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>hello-ejb</artifactId>
  <version>1.0</version>
  <packaging>ejb</packaging>

  <dependencies>
    <dependency>
      <groupId>jakarta.platform</groupId>
      <artifactId>jakarta.jakartaee-api</artifactId>
      <version>10.0.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-ejb-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <ejbVersion>3.2</ejbVersion>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>


πŸ›  Build Command:
mvn clean package

This generates:
target/hello-ejb-1.0.jar β€” ready for deployment.

βœ… 3. Deploy the JAR to a Jakarta EE Application Server
πŸ” How the Application Server Detects and Loads the EJB Module:
  1. JAR Placement:
    • Copy or drop the JAR file into the server’s deployments/ or autodeploy/ directory.
      • WildFly: /standalone/deployments/
      • Payara: Admin Console or auto-deploy/
      • Open Liberty: Configured via server.xml
  2. Deployment Scanning:
    • The server scans JARs at startup or runtime using a deployment scanner.
    • It identifies EJBs by:
      • Looking for classes annotated with @Stateless, @Stateful, @MessageDriven, etc.
      • Reading META-INF/ejb-jar.xml if present.
  3. Metadata Processing:
    • The server processes annotations and descriptors to:
      • Register EJBs in the container
      • Set up security roles, timers, interceptors, JNDI bindings, etc.
  4. Dependency Injection Setup:
    • Resources annotated with @Resource, @Inject, etc., are resolved.
    • EJBs are registered and bound to the global JNDI namespace.
  5. Application Ready:
    • The module is fully deployed and accessible to other components or external clients.



Module Summary and Topics
In this module, you performed the three major tasks required to deploy a bean on an EJB platform. These steps were:
  1. Create the Deployment Descriptor
  2. Generate the EJB jar file
  3. Deploy the jar file on the EJB platform

You used the Java EE Reference implementation to perform these tasks because it is the official reference implementation from Oracle and it is readily available and free. It is not suitable for production systems, only development and testing.

Write Customer Client - Exercise

Now, click the Exercise link to write a Customer program that is a client to a BankAccount bean. Write Customer Client - Exercise
You have used the classes that you downloaded to deploy and test the Hello session bean.

Write Customer Client - Exercise

Click the Exercise link below to deploy the BankAccount bean and test it with the provided BankCustomer client. Write Customer Client - Exercise
In the next module, you will be introduced to the code for the home and EJBObject interfaces.

SEMrush Software