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.
When I run this, I get an exception saying javax.naming.NameNotFoundException: HelloUserBean not bound
Whether I am doing something wrong in running client?
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.
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.
Try running the JNDI service's list function (look for the JNDI service first in jmx-console) rather than looking at the deployer service.
Joined: Oct 12, 2008
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?
Joined: Oct 12, 2008
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.
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.
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).
Joined: Oct 12, 2008
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.
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.