• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't run first Session Bean : NameNotFoundException

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Bartender
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Vish Shukla
    Ranch Hand
    Posts: 111
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 111
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 111
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Sheriff
    Posts: 10445
    227
    IntelliJ IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Vish Shukla
    Ranch Hand
    Posts: 111
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 10445
    227
    IntelliJ IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 111
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.

     
    Ranch Hand
    Posts: 45
    Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    You showed up just in time for the waffles! And this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic