3 Replies Latest reply on Jan 11, 2005 11:33 AM by anil.saldhana

    javax.naming.NameNotFoundException: comp not bound

    peake

      Trying to access an ejb from a java application. We have a delegate class which looks up the ejb successfully 'IF' you are a servlet within the container which includes the proper ejb references.

      It does so like this:
      Object obj = ctx.lookup("java:comp/env/ejb/WorkplaceSessionBean");
      Works well.
      But, if I write a java application and I use the delegate class to get the ejb, the above call now fails with the NameNotFoundException.

      As a quick test I wrote a look up in my application (non servlet) and it works if I do the following:
      // the physical name
      Object obj = ctx.lookup("ejb/WorkplaceSessionBean");

      Is there an environment setting/property I can set to still use the supplied, out of my control helper class of delegate:
      I am currently using the following:
      -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      -Djava.naming.provider.url=jnp://localhost:1099

      I am using 4.0.1 but do not believe that to be related. Seems I am missing a vm parameter.

        • 1. Re: javax.naming.NameNotFoundException: comp not bound
          peake

          The Answer:
          These are the properties:


          -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

          -Djava.naming.provider.url=jnp://JBOSS_HOST:1099/

          -Djava.security.auth.login.config=login.conf

          The login.conf file, pointed to by ?java.security.auth.login.config?, needs to contain:


          jboss_client {

          org.jboss.security.ClientLoginModule required;

          };



          Your remote application needs to authenticate before making any EJB (delegate) calls. This is the code:


          LoginContext lc = new LoginContext( "jboss_client", new TextCallbackHandler() );

          lc.login();

          The TextCallbackHandler is an example that prompts for credentials from the console. Your app may instead opt to implement a custom callbackhandler that gets credentials by some other means?depends on requirements.

          • 2. Re: javax.naming.NameNotFoundException: comp not bound

            There is a reason for this:

            the java:comp/env namespace is reserved for application components running in a managed environment. What this basically means is that each application component has its own private namespace bound to the context of
            java:comp/env.

            When running outside of the container, this does not work because the thin Java client does not have access to such a namespace. In this scenario, you would use the JNDI name directly, or develop an Application client that does have a java:comp/env namespace.

            • 3. Re: javax.naming.NameNotFoundException: comp not bound
              anil.saldhana

              Use the global JNDI namespace in JBoss. Don't bind to java:/