I have tested my first sessoin bean using Wildfly 8. I use the following code to obtain a proxy for the bean
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("java:global/EJBDemo/FirstDemoEJB");
When I print the object out I get the following output
Proxy for remote EJB StatelessEJBLocator{appName='', moduleName='EJBDemo', distinctName='', beanName='FirstDemoEJB', view='interface com.demo.ejb.FirstDemoEJBRemote'}
I can proceed with the RMI with the above lookup and get the desired result.
However, I observed that there are other lookup paths as listed by Wildfly at the time of deployment.
java:global/EJBDemo/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote
java:app/EJBDemo/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote
java:module/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote
java:jboss/exported/EJBDemo/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote
When I use the other lookup names names (part before the ! mark), I get the following output
EJBDemo/FirstDemoEJB -- service jboss.naming.context.java.app.TestEJB.EJBDemo.FirstDemoEJB
But I cannot RMI and get the desired result as in the java:global lookup.
My question is what does these other lookup paths listed by Wildfly mean? and can they be used for JNDI lookup as well? If so how to do it?
Before Java EE 6 every application server (Weblogic, JBoss, Glassfish, etc) had their own naming convention for JNDI then the applications weren't portables across servers.
In Java EE 6 the specification has standardized the JNDI address.
From https://docs.oracle.com/cd/E19798-01/821-1841/girgn/index.html :
Three JNDI namespaces are used for portable JNDI lookups: java:global, java:module, and java:app.
The java:global JNDI namespace is the portable way of finding remote enterprise beans using JNDI lookups. JNDI addresses are of the following form:
java:global[/application name]/module name/enterprise bean name[/interface name] Application name and module name default to the name of the application and module minus the file extension. Application names are required only if the application is packaged within an EAR. The interface name is required only if the enterprise bean implements more than one business interface.
The java:module namespace is used to look up local enterprise beans within the same module. JNDI addresses using the java:module namespace are of the following form:
java:module/enterprise bean name/[interface name] The interface name is required only if the enterprise bean implements more than one business interface.
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.
For example, if an enterprise bean, MyBean, is packaged within the web application archive myApp.war, the module name is myApp. The portable JNDI name is java:module/MyBean An equivalent JNDI name using the java:global namespace is java:global/myApp/MyBean.