adam bien's blog

EJB 3 Portability Issue: why JNDI names are not standardized? 📎

As I mentioned in my previous post,  the portability of Java EE 5 applications is much better, than in the old J2EE 1.4 world. I found one issue, which causes some effort - the lack of defined and unified JNDI-Naming and addressing. The glassfish applicationsserver uses the fully qualified name of the remote business interface as default. The JBoss appserver uses the name of the EJB with the "/remote" ending. So the following Session Bean:

package com.abien;

@Stateless
public class HelloWorldBean implements HelloWorld {
   
       
    public String sayHello(String hello){
        return "Echo from server: ";
    }
}

can be found with JBoss (with EJB3 support) using the following code-snippet:

        Context context = new InitialContext();
        HelloWorld helloWorld = (HelloWorld) context.lookup("HelloWorldBean/remote");

and Glassfish (v1 and v2), using the fully qualified name of the remote-business interface:

        Context context = new InitialContext();
        HelloWorld helloWorld = (HelloWorld) context.lookup(HelloWorld.class.getName());

I prefer the Glassfish style, because it fits better into the convention over configuration idea of the EJB3 spec. If you have a remote interface in the classpath, you can access it directly, using it's fully qualified name (typos are already recognized by the compiler...).

In the JBoss case you have to read the doc - which is not very intuitive, the names are not unique (the JNDI-names of beans from different packages would be the same), but the local and remote access can be better distinguished.

I really do not understand, why the JNDI naming schema is not standardized across the servers. I would prefer the Glassfish style, but regardless which strategy is used, it should be defined in the spec. The fully qualified name of the remote/local-interface would be absolutely sufficient...