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:
-
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
-
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.
-
Metadata Processing:
- The server processes annotations and descriptors to:
- Register EJBs in the container
- Set up security roles, timers, interceptors, JNDI bindings, etc.
-
Dependency Injection Setup:
- Resources annotated with
@Resource
, @Inject
, etc., are resolved.
- EJBs are registered and bound to the global JNDI namespace.
-
Application Ready:
- The module is fully deployed and accessible to other components or external clients.