I'm currently writing a set of EJBs that interface with some old EJB2 code. As part of this, I have an ejb-jar.xml
deployment descriptor that contains resource-refs and ejb-refs for the session beans. All of these definitions are basically identical - only the session bean's name differs between them. Obviously, this isn't ideal - every time I add a new bean, I have to copy and paste a large block of XML.
The structure looks something like this:
<ejb-jar
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
<enterprise-beans>
<session>
<ejb-name>/* redacted */</ejb-name>
<resource-ref>
<res-ref-name>/* redacted */</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<lookup-name>/* redacted */</lookup-name>
</resource-ref>
<ejb-ref>
<ejb-ref-name>/* redacted */</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>/* redacted */</home>
<remote>/* redacted */</remote>
</ejb-ref>
/* about 20 more ejb-refs later... */
</session>
/* several near identical session beans here ... */
</ejb-jar>
Is there any way to re-use these references in multiple definitions without duplication? Or, alternatively, is there a better way of achieving the same end result that I'm missing?
In my particular scenario, I was able to solve the issue by packaging the EJBs as a WAR instead of a plain JAR file - this allowed me to provide the references in web.xml
for the application as a whole, rather than on a per-bean level.