jboss.xml
...weblogic-ejb-jar.xml
<jboss>
<enterprise-beans>
<session>
<ejb-name>HelloSessionEJB</ejb-name>
<jndi-name>ejb/JHello</jndi-name>
</session>
</enterprise-beans>
</jboss>
...
...openejb-jar.xml
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>HelloSessionEJB</ejb-name>
<stateless-session-descriptor>
<jndi-name>ejb/JHello</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
...
...Without any doubts, I pretty clearly insist on binding my EJB to ejb/JHello in all of these vendor specific deployment descriptors.
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.0" configid="com/objecty/ejb">
<enterprise-beans>
<session>
<ejb-name>HelloSessionEJB</ejb-name>
<jndi-name>ejb/JHello</jndi-name>
</session>
</enterprise-beans>
</openejb-jar>
...
Now let's see what we have in our
ejb-jar.xml
...
<ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>demo-ejb</display-name>
<enterprise-beans>
<session>
<display-name>Hello SessionFacade</display-name>
<ejb-name>HelloSessionEJB</ejb-name>
<home>com.objecty.ejb.HelloSessionHome</home>
<remote>com.objecty.ejb.HelloSession</remote>
<ejb-class>com.objecty.ejb.HelloSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/EHello</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.objecty.ejb.HelloSessionHome</home>
<remote>com.objecty.ejb.HelloSession</remote>
<ejb-link>HelloSessionEJB</ejb-link>
</ejb-ref>
</session>
</enterprise-beans>
<assembly-descriptor/>
</ejb-jar>
...
It looks silly now, but let me explain. As you can see - we want our enterprise bean HelloSessionEJB to refer to itself binding into JNDI as ejb/EHello. All of the lines inside
So let's go ahead for now.
Here is our
web.xml
...
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
...
<ejb-ref>
<ejb-ref-name>ejb/WHello</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.objecty.ejb.HelloSessionHome</home>
<remote>com.objecty.ejb.HelloSession</remote>
<ejb-link>HelloSessionEJB</ejb-link>
</ejb-ref>
</web-app>
...
Again, it's pretty self explaining. With the help of ejb-ref we are saying that we want to refer to our enterprise bean from this Web application, and to use name ejb/WHello.
So, at this step we should have the following names binded to our entperprise bean in JNDI:
ejb/JHello - based on vendor-specific deployment descriptor
ejb/EHello - based on common spec ejb-jar.xml descriptor
ejb/WHello - based on common spec web.xml descriptor
Now, here is the list of our application servers. Meet them: IBM Websphere Application Server Community Edition 1.0.1.2, JBoss 4.0.4.GA and BEA WebLogic 9.1. Terrific band. :-) Everything is running on Mac OS X (even if there is no official support for that) and with JDK 1.5 (WASCE does not have official support of it either). Because of so many "unsupported" options I cannot insist that this is vendor nuance, but it does exist, so you need to be aware of it no matter what.
Take a wild-wild guess. Which JNDI names will be accessible from EJB and from Web Application in each of these three ASs? Write it down. Then go ahead and check how it is in real-life (Please note, that you can access only these names which I will mention nearby. Other modifications of them by adding/cutting java or comp. or env, or whatever else will not give you a positive result. Keep this in mind).
JBoss did a pretty fine job. From EJB we are able to access java:comp/env/ejb/EHello and ejb/JHello. From WAR we are able to access java:comp/env/ejb/WHello and again ejb/JHello. That means that even without having ejb-ref in ejb-jar/web XML files we still are able to access our JNDI binded enterprise bean by name ejb/JHello.
WebLogic was great as well. Actually results are the same (as JBoss), and names which are accessible from EJB and WAR are the same as well. That's pretty universal and standard. That's fine.
Now WASCE (Geronimo is the name). Here I see big difference. I was not able to find out how I can access ejb/JHello. Neither from EJB nor from WAR. No way to do that. The question - why do we need and use this jndi-name attribute in openejb-jar.xml is jumping in my head, but I do not have an answer. However, something still does work. We can access java:comp/env/ejb/EHello from EJB and java:comp/env/ejb/WHello from WAR. So ejb referencing does work and that makes sense.
Isn't it funny? So to be able to have standard application, where we are able to access JNDI binded EJB by one common name - the name should be "java:comp/env/ejb/TheName" and in all and every of these deployment descriptors (in all ejb-ref, in all jndi-name, etc.) we do need to have "ejb/TheName". This way, when we will port our application, we will not get into some stupid situation. However, this makes everything pretty confusing. We kinda define JNDI name in three different places. Weird, is it?
















