ejb-jar.xml
ejb-jar.xml is the optional deployment descriptor that’s packaged in an EJB module. ejb-jar.xml has two primary elements:
enterprise-beansis used to define beans, resources, and services used by the beansassembly-descriptoris used to declare security roles, method permissions, declarative transaction settings, and interceptors.
<ejb-jar
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd"
version="3.2">
<module-name>
<module-name> is used to define the name of the EJB module when deployed to the Enterprise server:
<ejb-jar...>
<module-name>action-bazaar-ejb</module-name>
</ejb-jar>
It’s only applicable to standalone EJB-JARS or EJB-JARS packaged in an EAR. It’s ignored if used within a .war file, in which case standard .war file module name rules apply.
Using <module-name> can standardize the name of your module when deployed, no matter the version number.
<enterprise-beans>
The <enterprise-beans> tag is used to define EJBs in an EJB-JAR module. You can use <session> or <message-driven> subtags to define session or message-driven beans.
<ejb-jar...>
<enterprise-beans>
<session>...</session>
</enterprise-beans>
</ejb-jar>
Tags to configure <session>
| Tag name | Description |
|---|---|
| ejb-name | A logical name for the session bean. Property "name" of @Stateless or @Stateful annotation. |
| mapped-name | A vendor-specific name for the bean. Property "mapped-Name" of the @Stateless or @Stateful annotation. |
| remote | Remote interface for the EJB: @Remote. |
| local | Local interface of the EJB: @Local. |
| service-endpoint | Web service endpoint interface for the EJB. Applies only to stateless beans: @WebService. |
| ejb-class | Fully qualified name of the bean class. |
| session-type | Type of session bean: @Stateless @Stateful @Singleton. |
| stateful-timeout | The amount of time a stateful bean can be idle before eligible for cleanup by the container: @StatefulTimeout. |
| timeout-method | The callback method for programmatically created timers: @Timeout. |
| timer | An EJB timer. Created by the container on deployment. Callbacks made to the timeout-method. |
| init-on-startup | Singleton bean should be created at deployment: @Startup. |
| concurrency-management-type | Specifies concurrency for singleton and stateful beans. May be either Bean or Container: @Concurrency-Management. |
| concurrent-method | Configures the container managed concurrency for a method. |
| depends-on | A list of one of more singleton beans that must be initialized before this singleton bean. Applies only to singleton beans. Use the ejb-link syntax to specify the dependencies: @DependsOn. |
| init-method | EJB 2-style create method for EJB 3 stateful EJBs: @Init. |
| remove-method | EJB 2-style remove method for EJB 3 stateful beans: @Remove. |
| async-method | Specifies method for asynchronous execution: @Asynchronous. |
| transaction-type | Specifies transaction for an EJB. May either Bean or Container: @TransactionManagement. |
| after-begin-method | Transaction callback method for a stateful bean to inform it that a new transaction has started: @AfterBegin. |
| before-completion-method | Transaction callback method for a stateful bean to inform it that a transaction is about to be committed: @BeforeCompletion. |
| after-completion-method | Transaction callback method for a stateful bean to inform it that a transaction has finished committing. Both commit and rollback will call this method: @AfterCompletion. |
| around-invoke | The method name on a class to be called during the around-invoke portion of an EJB invocation: @AroundInvoke. |
| around-timeout | The method name on a class to be called during the around-timeout portion of an EJB invocation: @AroundTimeout. |
| post-activate | Lifecycle callback method after activation: @PostActivate. |
| pre-passivate | Lifecycle callback method before passivation: @PrePassivate. |
| security-role-ref | References internal roles to external roles. |
| security-identity | Use the caller’s security identity to enforce security or override the caller’s identity for the specified “run-as” identity. |
| passivation-capable | Is the stateful bean able to be passivated? |
<ejb-jar...>
<enterprise-beans>
<message-driven>...</message-driven>
</enterprise-beans>
</ejb-jar>
Tags to configure <message-driven>
| Tag name | Description |
|---|---|
| ejb-name | The logical name for the MDB. Property "name" of @MessageDriven. |
| mapped-name | A vendor-specific name for the bean. Property "mappedName" of @MessageDriven. |
| ejb-class | Fully qualified name of the bean class. |
| messaging-type | Messaging type supported—that is, the message listener interface of the MDB. Property "messageListenerInterface" of @MessageDriven. |
| timeout-method | The callback method for programmatically created timers: @Timeout. |
| timer | An EJB timer. Created by the container on deployment. Callbacks made to the timeout-method. |
| transaction-type | Specifies transaction for an EJB. May be either Bean or Container. @TransactionManagement |
| message-destination-type | Expected type of the destination—that is, javax.jms.Queue. |
| message-destination-link | A vendor-specific mapping of a logical destination with the actual destination. |
| activation-config | Name/value pairs to configure the MDB when running in the EJB container. Property "activationConfig" of @MessageDriven. |
| around-invoke | The method name on a class to be called during the around-invoke portion of an EJB invocation: @AroundInvoke. |
| around-timeout | The method name on a class to be called during the around-timeout portion of an EJB invocation: @AroundTimeout. |
| security-role-ref | References internal roles to external roles. |
| security-identity | Use the caller’s security identity to enforce security or override the caller’s identity for the specified “run-as” identity. |
Interceptors
<ejb-jar...>
<interceptors>
<interceptor>...</interceptor>
</interceptors>
</ejb-jar>
Tags to configure <interceptor>
he <interceptors> tag is used to define interceptors for your EJB module
| Tag name | Description |
|---|---|
| description | Description of this interceptor. |
| interceptor-class | The fully qualified name of the class to serve as your interceptor. |
| around-invoke | The method name on a class to be called during the around-invoke portion of an EJB invocation: @AroundInvoke. |
| around-timeout | The method name on a class to be called during the around-timeout portion of an EJB invocation: @AroundTimeout. |
| around-construct | The method name on a class to be called during an object’s construction: @AroundConstruct. |
| post-activate | Lifecycle callback method after activation: @PostActivate. |
| pre-passivate | Lifecycle callback method before passivation: @PrePassivate. |
<assembly-descriptor>
The <assembly-descriptor> tag is used to define declarative transactions, security role and method permissions, and interceptor bindings:
<ejb-jar...>
<assembly-descriptor>...</assembly-descriptor>
</ejb-jar>
<security-role>
The <security-role> tag is used to define security roles used in the application:
<ejb-jar...>
<assembly-descriptor>
<security-role>...</security-role>
</assembly-descriptor>
</ejb-jar>
The corresponding annotation is @DeclareRoles.
Tag to configure <security-role>
| Tag name | Description |
|---|---|
| role-name | The name of the security role. Example: @DeclareRoles({"Admin", "User"}). |
<method-permission>
The <method-permission> tag is used to define what roles are allowed to execute which EJB methods:
<ejb-jar...>
<assembly-descriptor>
<method-permission>...</method-permission>
</assembly-descriptor>
</ejb-jar>
The corresponding annotation is @RolesAllowed
Tags to configure <method-permission>
| Tag name | Description |
|---|---|
| role-name | Name of the roll allowed to execute the method. This or unchecked may be used but not both. |
| unchecked | Specifies that all roles are allowed to execute the method. This or role-name may be used but not both. |
| method | Specifies the name of the EJB (as specified in ) and the name of the method to secure. |
<container-transaction>
<ejb-jar...>
<assembly-descriptor>
<container-transaction>...</container-transaction>
</assembly-descriptor>
</ejb-jar>
The corresponding annotation is @TransactionAttribute
Tags to configure <container-transaction>
| Tag name | Description |
|---|---|
| trans-attribute | Specifies the transaction attribute of the method. Valid values are Required, RequiresNew, NotSupported, Supports, Never, Mandatory. |
| method | Specifies the name of the EJB (as specified in <session> <ebj-name>) and the name of the method to secure. |
<interceptor-binding>
The `<interceptor-binding>` tag is used to bind interceptors to EJBs at either a class level or a method level:
<ejb-jar...>
<assembly-descriptor>
<interceptor-binding>...</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
This tag is similar to the @Interceptors annotation.
Tags to configure <interceptor-binding>
| Tag name | Description |
|---|---|
ejb-name | Specifies the name of the EJB, as specified in <session><ebj-name> or the "name" element of @Stateless or @Stateful. This will apply the interceptor to all methods of the class. A value of “*” will create a default interceptor and bind to all EJB and MDB in the ejb-jar.xml file or .war file. |
<interceptor-order> <interceptor-class>..</> </interceptor-order> | A list of interceptor classes that are bound to the contents of the ejb-name element. The interceptor-order is optional, and if used specifies the order in which the interceptors are to be called. No corresponding annotation for specifying order. |
exclude-default-interceptors | Specifies that default interceptors aren’t to be applied to the EJB class or method: @ExcludeDefaultInterceptors. |
exclude-class-interceptors | Specifies that class interceptors aren’t to be applied to the EJB class or method: @ExcludeClassInterceptors. |
method | Specifies which method. |
<message-destination>
<ejb-jar...>
<assembly-descriptor>
<message-destination>...</message-destination>
</assembly-descriptor>
</ejb-jar>
The <message-destination> tag specifies a logical destination name that’s later mapped to a physical destination by the deployer:
Tags to configure <message-destination>
| Tag name | Description |
|---|---|
message-destination-name | Specifies a name for a message destination. This name must be unique among the names of message destinations within the ejb-jar.xml or .war file. |
mapped-name | An application-specific, nonportable (not required to be supported) name that this destination should be mapped to. |
lookup-name | The JNDI name to be looked up to resolve the message destination. This is typically the location in JNDI where your application server has put the destination. |
<exclude-list>
The <exclude-list> tag specifies a list of methods that are denied permission to execute:
<ejb-jar...>
<assembly-descriptor>
<exclude-list>...</exclude-list>
</assembly-descriptor>
</ejb-jar>
This tag is equivalent to the @DenyAll annotation
Tags to configure <exclude-list>
| Tag Name | Description |
|---|---|
method | Specifies the name of the EJB (as specified in <session><ebj-name>) and the name of the method to secure. |
<application-exception>
The <application-exception> tag specifies a list of application-specific exceptions that may be thrown by your EJBs and MDBs:
<ejb-jar...>
<assembly-descriptor>
<application-exception>...</application-exception>
</assembly-descriptor>
</ejb-jar>
By listing application exceptions, you can configure whether the exception will cause a rollback of the current transaction. By default, an EJBException will trigger a rollback but application exceptions do not. This tag corresponds to the @ApplicationException annotation.
Tags to configure <application-exception>
| Tag name | Description |
|---|---|
exception-class | Specifies the fully qualified name of the exception class. |
rollback | Specifies if the container should roll back the transaction before throwing the exception up to the client. |