Search code examples
jndijava-ee-6ejb-3.1

JNDI local lookup for enterprise beans within the same module


Here are some lines from the Java EE 6 tutorial about JNDI local lookup.

The java:app namespace is used to look up local enterprise beans packaged within the same application. That is, the enterprise bean is packaged within an EAR file containing multiple Java EE modules. JNDI addresses using the java:app namespace are of the following form:

java:app[/module name]/enterprise bean name[/interface name]

The module name is optional. The interface name is required only if the enterprise bean implements more than one business interface.

My question is: Why is the module name optional? What if there are two enterprise beans with the same name in two different modules?


Solution

  • The module name is not optional if you deploy an EAR. The module name is omitted if you deploy a WAR or EJB JAR directly without packaging it within an EAR because in that case, there is only one module so there is no ambiguity.