| Author |
Can't run first Session Bean : NameNotFoundException
|
Vish Shukla
Ranch Hand
Joined: Oct 12, 2008
Posts: 100
|
|
Hi,
I have been striving to run my first Session bean but all in vain. I searched for tutorials for EJB3 + JBoss + Eclipse but didn't get helpful links, so from the code snippets of different tutorials & books, I tried to setup development environment and run my first Bean. Here is what I did for this.
Installed JDK 1.6, set JAVA_HOME.Installed JBoss 5.0, set environment variable JBOSS_HOME.Configured JBoss in Eclipse 3.4.In eclipse, created new EJB project with client. Code is shown below.Added jar with session beans in the build path of Client application. [Is this what I should be doing?]Started JBoss, published my application and tried to run file-with-main from Right Click->Run As Java Application.
Session Bean:
Business Interface:
Client:
When I run this, I get an exception saying javax.naming.NameNotFoundException: HelloUserBean not bound
Whether I am doing something wrong in running client? Should client be running in EJB container? I am having no clue what to do next. Please help.
Thanks in advance.
|
Thanks & Regards,
Vishal S Shukla (SCJP 93%, SCWCD 94%, SCBCD 100%)
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
JBoss gives you a view of JNDI via its jmx-console. Try going to http://localhost:8080/jmx-console and running the JNDI service list view. This will let you see what and where things are bound in JNDI.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Vish Shukla
Ranch Hand
Joined: Oct 12, 2008
Posts: 100
|
|
Hi Paul,
Thanks for prompt reply. I tried to do as per you suggested. I found HelloUserBean at couple of places. I don't exactly know where should I be searching for entry of HelloUserBean. One is under jboss.deployment which is id="jboss.j2ee:ear=EjbWithClient1EAR.ear,jar=EjbWithClient1.jar,name=HelloUserBean,service=EJB3",type=Component and the other is under jboss.j2ee which is ear=EjbWithClient1EAR.ear,jar=EjbWithClient1.jar,name=HelloUserBean,service=EJB3.
I guess bean is properly being registered with JNDI but still not getting any clue whats going wrong.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Try running the JNDI service's list function (look for the JNDI service first in jmx-console) rather than looking at the deployer service.
|
 |
Vish Shukla
Ranch Hand
Joined: Oct 12, 2008
Posts: 100
|
|
Paul,
I think I am too new to EJB & JBoss to completely understand what you said. I checked out service=JNDIView link in the jmx-console but don't know how to interpret it. This is showing attribute details like State, StateString, HANamingService etc.
Is that what you wanted me to check out?
I also checked details in jboss.j2ee which is ear=EjbWithClient1EAR.ear,jar=EjbWithClient1.jar,name=HelloUserBean,service=EJB3. Its showing
CreateCount & CurrentCount = 0. Is this expected or count should be positive before the lookup takes place?
|
 |
Vish Shukla
Ranch Hand
Joined: Oct 12, 2008
Posts: 100
|
|
Paul,
I checked out other threads for viewing JNDI namespace. Here I am copying Global JNDI Namespace I got in jmx-console. Paul or someone else please help to interpret it and get to the next step in solving my issue.
Global JNDI Namespace
Its really frustrating that I am not even being able to run Helloworld program for EJB3.
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8208
|
|
The JNDIView presents a tree representation of the JNDI contents. As per your output:
Vish Shukla wrote:
you should be using "EjbWithClient1EAR/HelloUserBean/remote" as the jndi-name to lookup the remote view of the bean.
|
[My Blog] [JavaRanch Journal]
|
 |
Vish Shukla
Ranch Hand
Joined: Oct 12, 2008
Posts: 100
|
|
Jaikiran,
you are bang on... Its works fine now..... Thanks for getting it solved.
But there is other issue right after that when I tried to use my servlet as java client with same EJB deployed. I used the same code for getting reference of remote interface but I get following exception.
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
Is there any difference in having stand-alone java application or servlet as EJB client? I am not using dependency injection in client.
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8208
|
|
You'll have to set the client classpath to point to the JBOSS_HOME/client/jbossall-client.jar (and the jars referenced in it's META-INF/MANIFEST.MF).
|
 |
Vish Shukla
Ranch Hand
Joined: Oct 12, 2008
Posts: 100
|
|
Hi Jaikiran,
Thanks for your support. I tried it by adding few jars of jboss(because I am not sure exactly which jars are required in the client class path) in the "lib" folder of the web application and the exception is solved. But I am getting AccessControlException on port 1099. I have created separate thread for the same. Here is the link Failed to connect to server localhost:1099, RemoteAccessException, SocketException
I am now desperate to get it my session bean running with web client.
|
 |
Kuldip Shetty
Ranch Hand
Joined: Jan 07, 2010
Posts: 37
|
|
For Standalone remote EJB java client use the InitialContext(prop) constructor and for EJB Client running under JBoss Application Server we can use default InitialContext() constructor. Using default constructor it does local lookup and for remote lookup we need to set the initial context parameters using constructor InitialContext(prop). Hope this will resolve the EJB lookup issue.
Kuldip
|
 |
 |
|
|
subject: Can't run first Session Bean : NameNotFoundException
|
|
|