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;

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...

NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns


Totally agree that it should be standard, I've been yammering at Sun to fix this for 2 years.

Your JBoss example is incorrect, it should be "myEarName/HelloWorldBean/remote". I don't think it is at all common to have beans with the same name in different packages in the same EAR.

BTW, the GlassFish approach is a very bad one, since if I deploy the same EAR twice, or two EARs with the same EJB JAR, I will get my beans bound to the same names. The whole *point* of having an appserver is you can isolate different deployments.

Posted by Gavin King on December 13, 2006 at 06:06 PM CET #

Hi Gavin,

thank you for your comment. Should we start a JSR for this? :-)
I forgot in the JBoss case the prefix - you are right. But if you deploy only the ejb-jar - there is no prefix. Also in Glassfish case a defined prefix or "namespace" could fix the problem.

"I don't think it is at all common to have beans with the same name in different packages in the same EAR."

Just try to deploy the JBoss-EJB-Tests and you will run into that issue:-)

thank you very much for your comment,


Posted by Adam Bien on December 14, 2006 at 01:13 PM CET #

Actually, JBoss is even better than I said. That is not the classname in the JNDI name, it is the EJB name, which is required by the spec to be unique in an ejb-jar. So there is actually no possibility of a name clash at all!

Well, unless you deploy the ejb-jar outside of an EAR. Most people use EARs in practice.

I think we will be able to fix this in the next rev of EJB.

Posted by Gavin King on December 14, 2006 at 04:14 PM CET #

Hi Gavin,

yes, you are right. The EJB-Name is derived from the Bean name per default. If you provide one, it has impacts to the JNDI name.

"Well, unless you deploy the ejb-jar outside of an EAR. Most people use EARs in practice."

Yes except, your persistence-tests :-)

thank you for your comment!,


Posted by Adam Bien on December 20, 2006 at 11:53 AM CET #

I absolutely agree with you. Right now I'm working with 3 different ejb containers (Glassfish, JBoss and OpenEjb) and they use totally different conventions for ejb names. It's incredible, isn't it?

Posted by Filippo on December 24, 2006 at 10:25 AM CET #

The Jboss approach does make more sense from a 'multiple implementations, one remote interface' approach.

I'm still getting frustrated/confused between the different naming, particuarly when dealing with WAR accessing remotely, locally, from outside an EAR, from within an EAR.

There should be some specification action quickly on this, and hurting the 'portability' cause significantly.

Posted by dhartford on March 22, 2007 at 04:06 PM CET #

Excellent post on the variations in vendor implementations of global JNDI names. Sadly, we'll never see any spec action on this; or rather we already have, the j2ee application client is the offical answer.

It should be noted that the OpenEJB style of defining a JNDI name can be changed to just about any format you like. You supply a template, we fill in the values:

Posted by David Blevins on September 22, 2007 at 04:42 PM CEST #

Many thanks for your useful insights.
Had been banging my head against a brick wall trying to understand why JNDI lookup in JBoss was not working whilst following along with examples in APress's Beginning Java EE 5 Platform (Chapter 9)

Posted by Jeremy Flowers on March 06, 2008 at 02:23 PM CET #

This is a the most useful article on the internet, ever. I m trying "run first EJB" very long time and, I had a lot of trouble with JDNI names, deploying and loong configuration. Your Bean.clas.getName() ond ClassFish works fine and firstly for ME, very thx. Oh man, thx. This article helped me to break bar between "reading" and "working" - Marta Jandova bless you !

Posted by AZOR on May 10, 2008 at 03:53 AM CEST #

How do you find the session bean if deployed to a tomcat 5.x server?

Posted by Viggo on February 23, 2009 at 07:09 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments