A sample ejb-jar.xml (EJB 3.0)

ejb-jar.xml is optional starting from EJB 3.0. Annotations are extensively used to declare metadata in place of descriptor elements. In certain cases, ejb-jar.xml is still necessary, and 2 such cases I can think of are the declaration of env-entry and default interceptor.
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<enterprise-beans>
<session>
<ejb-name>TestBean</ejb-name>
<ejb-ref>
<ejb-ref-name>ejb/fooremote</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>test.FooRemoteIF</remote>
</ejb-ref>
<env-entry>
<description>admin email</description>
<env-entry-name>adminEmail</env-entry-name>
<env-entry-value>admin@example.x</env-entry-value>
</env-entry>
</session>
</enterprise-beans>

<interceptors>
<interceptor>
<interceptor-class>test.Interceptor1</interceptor-class>
</interceptor>
</interceptors>

<assembly-descriptor>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>test.Interceptor1</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
This ejb-jar.xml assumes that TestBean is already annotated with either @Stateless or @Stateful. The descriptor adds a env-entry resource to this session bean's naming environment. This env-entry can be injected into TestBean class, or looked up in TestBean's naming environment.

The interceptor-binding element binds Interceptor1 to all EJBs packaged in the current ejb jar.

Followers

Pageviews Last 7 Days