views:

50

answers:

1

I have a stateless bean with some properties:

  1. It's a EJB3
  2. class AddressFacade
  3. implements AddressFacadeRemote
  4. it's inside a ejb-jar (MyJAR.jar)
  5. it's in a EAR (MyEAR).

My application server (Weblogic) generated this name (jndiName/mappedName):

MyEARMyJAR_jarAddressFacade_AddressFacadeRemote

I can't use injection, so I'll make a lookup with this name.

The question is: this name always will be the same if I maintain the same EAR,JAR,Class and interface name? Or it can change from application servers?

+1  A: 

The question is: this name always will be the same if I maintain the same EAR,JAR,Class and interface name? Or it can change from application servers?

JNDI names are not standardized in Java EE 5 and will change from one application server to the other. Adam Bien wrote a nice post illustrating this:

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("myEarName/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());

One decent way to handle this is to use a ServiceLocator and "pluggable" application server specific strategies. Have a look at at ServiceLocator, JNDI Naming Helper and Java EE 5.

In Java EE 6, things are fixed and we finally have Portable Global JNDI Names.

Pascal Thivent
@pascal: tks a lot!
Topera
@Topera You're welcome.
Pascal Thivent