Link to home
Start Free TrialLog in
Avatar of sjhamb
sjhamb

asked on

javax.naming.NameNotFoundException: ejb not bound. URGENT PLEASE!!!

Hi,

I have a problem locating the home interface of an stateless session bean. The application server is JBoss. The beans seem to

deploy without errors on the app server. I have been fighting with problem for 2 days now.

Following is the code i am using

try {
     Context context = new InitialContext();
     Object ref = context.lookup("ejb/Lego");
     home = (LegoHome)PortableRemoteObject.narrow(ref,LegoHome.class);
} catch (NamingException e) {
    e.printStackTrace();
}

I have also tried using
Object ref = context.lookup("java:comp/env/ejb/Lego");
to lookup the EJB.

The Output from server on deployment is:

[EjbModule] Deploying Lego
[StatelessSessionInstancePool] Started jboss.j2ee:jndiName=ejb/Lego,plugin=pool,service=EJB
[StatelessSessionContainer] Started jboss.j2ee:jndiName=ejb/Lego,service=EJB
[EjbModule] Started jboss.j2ee:module=LegoEJB.jar,service=EjbModule

Contents of my jndi.properties file:

[EjbModule] Deploying Lego
[StatelessSessionInstancePool] Started jboss.j2ee:jndiName=ejb/Lego,plugin=pool,service=EJB
[StatelessSessionContainer] Started jboss.j2ee:jndiName=ejb/Lego,service=EJB
[EjbModule] Started jboss.j2ee:module=LegoEJB.jar,service=EjbModule

Contents of application.xml are:
<application>
      <display-name>My Test Application</display-name>
      <module>
            <ejb>LegoEJB.jar</ejb>
      </module>
      <module id="WarModule_1">
            <web>
                  <web-uri>LegoWeb.war</web-uri>
                  <context-root>/test</context-root>
            </web>
      </module>
      <module id="EjbModule_1">
            <ejb>LegoEJB.jar</ejb>
      </module>
</application>

When I try to access it from Servlet I get Following Error on JBOSS Console:
javax.naming.NameNotFoundException: ejb not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)

It Seems I am messing up with some configuration problem somewhere. Please Help Urgent
Please Let me know what all do i have to configure to get this running.
Avatar of vzilka
vzilka

Please post your ejb-jar.xml and jboss.xml files in here.
Avatar of sjhamb

ASKER

contents of jboss.xml

      <session>
         <ejb-name>Lego</ejb-name>
         <jndi-name>ejb/Lego</jndi-name>
      </session>

Contents of ejb-jar.xml

      <session>
         <description><![CDATA[1st Stateless Session Bean]]></description>
         <display-name>First_Stateless_Bean</display-name>

         <ejb-name>Lego</ejb-name>

         <home>test.interfaces.LegoHome</home>
         <remote>test.interfaces.Lego</remote>
         <ejb-class>test.ejb.LegoBean</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Container</transaction-type>
            
      </session>

Open your jmx console (http://localhost:8080/jmx-console) and check the JNDI service.
Run the list method of the service, to see the JNDI tree of your server. Does the Lego EJB appears there?
Avatar of sjhamb

ASKER

I don't see anything like "list method" there ....

I can see following enteries in jmx-console under jboss.j2ee head:

jndiName=ejb/Lego,plugin=pool,service=EJB
jndiName=ejb/Lego,service=EJB
module=LegoEJB.jar,service=EjbModule

and have tried using Invoke against start/ cerate etc... it works fine but still am facing this problem.
It means your EJB is succesfully deployed.
Can you try:
Object ref = context.lookup("ejb/Lego");
Instead of your own lookup line?
Avatar of sjhamb

ASKER

Have tried that ... doesn't work...
Avatar of sjhamb

ASKER

Anyone Else ... ??
Are you using ejb-references?
Which JBoss version is that?
Avatar of sjhamb

ASKER

JBOSS Version 3.2.3

I did not get your first question though
Are you using ejb-ref in your web.xml?
Can you access other ejbs/remote objects from your servlet? Can you access a data source for example?
I try to narrow down your problem, since the EJB is deployed, it is not clear why the name not found exception
Avatar of sjhamb

ASKER

No, I am not using that....i tried using that but then i get errors while deployment...

org.jboss.deployment.DeploymentException: Error during deploy; - nested throwable: (javax.naming.NamingException: ejb-ref: ejb/Lego, no ejb-link in web.xml and no jndi-name in jboss-web.xml)
OK. Let's try another thing.
The context has a list() method. Can you print it to the screen (system.out.println, or to the output html page) and then we'll see what is defined in your context?
It returns a NamingEnumeration object, it should be easy to print.
Avatar of sjhamb

ASKER

I get javax.naming.NotContextException at line 2

I have written following code to check what you suggested:

Context context = new InitialContext();
                                    
NamingEnumeration nE = context.list("ejb/Lego");

while(nE.hasMoreElements()){
      System.out.println(nE.toString());
      nE.nextElement();
}
Just context.list() without the ejb/Lego as a parameter
Avatar of sjhamb

ASKER

list method requires a parameter.
I tried calling it like:
NamingEnumeration nE = context.list("");

Result:
[STDOUT] org.jnp.interfaces.NamingEnumerationImpl@1c37b8f

21 times on console
You need to iterate the items in the enumeration.

Try this code piece, it prints the entire JNDI tree.

  void printTree(Context c,Context subContext, String contextName, JspWriter out, String prefix) throws NamingException, IOException {
    System.out.println(contextName);
   
    NamingEnumeration ne = c.listBindings(contextName);
     
    while (ne.hasMore()) {
      Binding b = (Binding)ne.next();

      if (b.getObject() instanceof Context) {
        out.println(prefix + "<b>" + b.getName() + "<b><BR>");
        printTree(subContext,(Context)b.getObject(),b.getName(),out,"--\\" + prefix);
      } else {      
        out.println(prefix + b.getName() + "<BR>");
      }
    }
  }

main() {
  InitialContext ic = new InitialContext();

  printTree(ic,ic,"",out, "");
}

Where out is an outputstream.
Avatar of sjhamb

ASKER

I ran the code you had sent and "Lego" was there in the output.
Avatar of sjhamb

ASKER

What Next? Any Clues?
Just lookup Lego instead of ejb/Lego, it looks like it should work.
Avatar of sjhamb

ASKER

javax.naming.NameNotFoundException: Lego not bound
Can you post the entire output of the method?
Avatar of sjhamb

ASKER

Sure, Here it is:

jmx
jmx
invoker
invoker
RMIAdaptor
rmi
rmi
RMIAdaptor
OIL2XAConnectionFactory
HTTPXAConnectionFactory
ConnectionFactory
UserTransactionSessionFactory
HTTPConnectionFactory
XAConnectionFactory
invokers
invokers
0.0.0.0
0.0.0.0
pooled
wks_05
wks_05
jrmp
http
UserTransaction
RMIXAConnectionFactory
UILXAConnectionFactory
UIL2XAConnectionFactory
queue
queue
A
testQueue
ex
DLQ
D
C
B
topic
topic
testDurableTopic
testTopic
securedTopic
console
console
PluginManager
UIL2ConnectionFactory
UILConnectionFactory
RMIConnectionFactory
ejb
ejb
Lego
OIL2ConnectionFactory
UUIDKeyGeneratorFactory
Avatar of sjhamb

ASKER

It started working on its own...
I don't know what ....
It Just Worked ... All of a sudden
ASKER CERTIFIED SOLUTION
Avatar of vzilka
vzilka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sjhamb

ASKER

Nope... Thanks for your patience and support ...
could you please send me what you did to run the bean