Global JNDI names are assigned according to the following precedence rules:
A global JNDI name assigned in the sun-ejb-jar.xml, sun-web.xml deployment descriptor file has the highest precedence. See Mapping References.
A global JNDI name assigned in a mapped-name element in the ejb-jar.xml, web.xml deployment descriptor file has the second highest precedence. The following elements have mapped-name subelements: resource-ref, resource-env-ref, ejb-ref, message-destination, message-destination-ref, session, and entity.
A global JNDI name assigned in a mappedName attribute of an annotation has the third highest precedence. The following annotations have mappedName attributes: @javax.annotation.Resource, @javax.ejb.EJB, @javax.ejb.Stateless.
A default global JNDI name is assigned in some cases if no name is assigned in deployment descriptors or annotations.
For component dependencies that must be mapped to global JNDI names, the default is the name of the dependency relative to java:comp/env. For example, in the @Resource(name="jdbc/Foo") DataSource ds; annotation, the global JNDI name is jdbc/Foo.