The following XML elements in the GlassFish Server deployment descriptors map resource references in application client, EJB, and web application components to JNDI names configured in the GlassFish Server:
JNDI names for EJB components must be unique. For example, appending the application name and the module name to the EJB name is one way to guarantee unique names. In this case, mycompany.pkging.pkgingEJB.MyEJB would be the JNDI name for an EJB in the module pkgingEJB.jar, which is packaged in the pkging.ear application.
These elements are part of the glassfish-web.xml, glassfish-application-client.xml, glassfish-ejb-jar.xml, and glassfish-application.xml deployment descriptor files. For more information about how these elements behave in each of the deployment descriptor files, see Appendix C, Elements of the GlassFish Server Deployment Descriptors, in Oracle GlassFish Server 3.1 Application Deployment Guide.
The rest of this section uses an example of a JDBC resource lookup to describe how to reference resource factories. The same principle is applicable to all resources (such as JMS destinations, JavaMail sessions, and so on).
The @Resource annotation in the application code looks like this:
@Resource(name="jdbc/helloDbDs") javax.sql.DataSource ds;
This references a resource with the JNDI name of java:jdbc/helloDbDs. If this is the JNDI name of the JDBC resource configured in the GlassFish Server, the annotation alone is enough to reference the resource.
However, you can use a GlassFish Server specific deployment descriptor to override the annotation. For example, the resource-ref element in the glassfish-web.xml file maps the res-ref-name (the name specified in the annotation) to the JNDI name of another JDBC resource configured in the GlassFish Server.
<resource-ref> <res-ref-name>jdbc/helloDbDs</res-ref-name> <jndi-name>jdbc/helloDbDataSource</jndi-name> </resource-ref>