Can I deploy two beans in a single jar file? If so, how?
Created May 4, 2012
Yes, multiple EJBs can be deployed in a single jar file. The deployment is somewhat different between EJB 1.0 and EJB 1.1.
In EJB 1.0 each bean has a separate serialized deployment descriptor. All of the bean classes and deployment descriptors are placed in the jar file along with the manifest file named META-INF/MANIFEST.MF. The manifest file must contain an entry for each bean that names the bean's deployment descriptor. For example, the following manifest is for a jar file that contains two deployment descriptors:
Name: BeanADD.ser Enterprise-Bean: True Name: dirname/BeanBDD.ser Enterprise-Bean: True
Note that a blank line is required between the entries in the manifest file.
In EJB 1.1 and in the draft EJB 2.0 specification, instead of a manifest and serialized deployment descriptors there is a single shared XML deployment descriptor named META-INF/ejb-jar.xml. Within ejb-jar.xml there must be either a <session> or <entity> element for each bean in the jar file. For example, the following XML fragment is for a jar file that contains one entity and one session bean:
<ejb-jar> <enterprise-beans> <session> <ejb-name>MySessionBean</ejb-name> ... other xml elements describing the bean's deployment properties ... </session> <entity> <ejb-name>MyEntityBean</ejb-name> ... other xml elements describing the bean's deployment properties ... </entity> </enterprise-beans> </ejb-jar>
The EJB 2.0 draft specification for deployment descriptors differs from EJB 1.1 only in the addition of XML elements for describing additional bean properties.