- This topic has 5 replies, 3 voices, and was last updated 20 years, 4 months ago by Riyad Kalla.
-
AuthorPosts
-
vanstonecypherMemberI’m experimenting with building an EJB/JSP app using MyEclipse and JBoss 3.2.5. I’m quite comfortable with building web apps, so this is really an excuse to play with EJBs and learn something new. 😀
Anyway, I created three projects: a web module, ejb module and enterprise application.
The application module just contains the other two and I use MyEclipse to deploy it to JBoss.
The ejb module has a single session bean with the following XDoclet comment:
* @ejb.bean name = "HelloBean" * type = "Stateless" * display-name = "HelloBean" * description = "HelloBean EJB" * view-type = "remote" * jndi-name = "ejb/HelloBean"
It is configured with the “Standard EJB” XDoclet with the following options: deploymentdescriptor, fileset, homeinterface, jboss, packageSubstitution, remoteinterface and session. I can build the EJB just fine and all seems to work well my jboss.xml contains:
<session> <ejb-name>HelloBean</ejb-name> <jndi-name>ejb/HelloBean</jndi-name> </session>
In the web module I built a jsp with the following init function:
<%! private HelloBean hello = null; public void jspInit() { try { final InitialContext ic = new InitialContext(); Object objRef = ic.lookup("HelloBean"); HelloBeanHome home = (HelloBeanHome)PortableRemoteObject.narrow(objRef, HelloBeanHome.class); hello = home.create(); } catch (Exception ex) { // should do something usefull.... } } %>
All of this works fine and I can access the bean in the JSP, but here is where I’m confused. In the previous definition, the jni-name parameter is “ejb/HelloBean” while I had to use “HelloBean” in the lookup method. Why is that? Shouldn’t it be “ejb/HelloBean”? (That doesn’t work by the way, I’ve tried it.)
When I look at JBoss’ JMX Management Console I see:
jboss.j2ee * jndiName=HelloBean,plugin=pool,service=EJB * jndiName=HelloBean,service=EJB
I’m sure I’m missing something simple, but I don’t know what. Anyone have a suggestion?
Riyad KallaMemberSince this is a general EJB question I’m going to move it to Random Thoughts, but will also ask our EJB guy if he has any ideas that might help you.
GregMemberI had to lookup a tutorial to get some clues about this. Here is a link to a helpful doc.
http://www.informit.com/articles/article.asp?p=28281&seqNum=3
Here are a couple of interesting sections.
... The J2EE specification recommends that all references to enterprise beans be organized in the java:comp/env/ejb context of the application component's environment. ... An ejb-ref-name element that specifies the name of the reference relative to the java:comp/env context. To place the reference under the recommended java:comp/env/ejb context, use an ejb/link-name form for the ejb-ref-name value. ...
An EJB reference is scoped to the application component whose declaration contains the ejb-ref element.
So basically, in the generated xml files ejb/HelloBean is short for java:comp/env/ejb/HelloBean. And accessing just HelloBean works because there isn’t another HelloBean defined elsewhere.
vanstonecypherMemberThanks for the link, it has plenty of information to digest. However I don’t think it answers my basic question. What I was doing was looking through Sun’s J2EE Tutorial and using their code examples to build the HelloBean. However, when I used “ejb/HelloBean” I got the following exception:
javax.naming.NameNotFoundException: ejb not bound
After digging around in the deployed directories and generated xml files, I found that ebj-jar.xml had the following entry:
<ejb-name>HelloBean</ejb-name>
When I changed it to:
<ejb-name>ejb/HelloBean</ejb-name>
The reference in the JSP worked (although “java:comp/env/ejb/HelloBean” does not.) My question now is what “name” am I referencing in the JSP? I thought it was the JNDI name (ejb/HelloBean) but it doesn’t seem to be. I don’t really want to edit the generated files since it seems to defeat the purpose (which I why I wanted to use MyEclipse in the first place!) Am I specifying the XDoclet parameters incorrectly, deploying the app incorrectly, or just not understanding how everything is supposed to be referenced? 😯
vanstonecypherMemberI thought I’d post the solution in case someone else is having this problem. As I thought, it turns out to be something simple. I didn’t have the destDir set for the jboss XDoclet to src/META-INF, so the jboss.xml file was not in the right place. By default jboss simply uses the bean name, which explains my confusion. 😳
Riyad KallaMemberThanks for posting the solution, this is very helpful to keep this forums a valueable resource for the users.
-
AuthorPosts