4 Replies Latest reply on Oct 12, 2005 12:28 PM by jboss_anto

    javax.naming.NameNotFoundException: comp not bound

    jboss_anto

      Hi everybody,
      I have the following problem when I connect with a client to a Session Bean EJB using JBoss 4.0.3

      Starting to resolve HelloWorld Object from Context Object
      javax.naming.NameNotFoundException: comp not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:252)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at client.HelloWorldClient.main(Unknown Source)



      I have deployed the ear file into JBOSS_HOME/server/default/deploy and started Jboss with "run.sh" ..

      Here the code of the files:

      Client code:


      public class HelloWorldClient
      {
      public static void main( String [] args )
      {
      /*
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      System.out.println(env.toString());
      env.put(Context.PROVIDER_URL,"jnp://192.168.7.19:1099");
      */
      try
      {
      Context iniCtx = new InitialContext();
      System.out.println("Starting to resolve HelloWorld Object from Context Object");
      Context ctx = (Context) iniCtx.lookup("java:comp/env");
      Object obj = ctx.lookup("ejb/HelloWorld" );
      System.out.println("Resolve RMI Object from Naming Context");
      HelloWorldHome home =
      (HelloWorldHome)javax.rmi.PortableRemoteObject.narrow(
      obj, HelloWorldHome.class );
      HelloWorld helloWorld = home.create();
      System.out.println( helloWorld.hello());
      helloWorld.remove();
      }
      catch ( Exception e )
      {
      e.printStackTrace();
      System.out.println( "Exception: " + e.getMessage() );
      }
      }




      META-INF deployment files:

      application.xml:

      <?xml version="1.0" encoding="UTF-8"?>

      <display-name>Test application</display-name>
      Mail forwarding application

      Project.jar




      ejb-jar.xml:


      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      JBoss Hello World Applicaiton
      <display-name>Hello World EJB</display-name>
      <enterprise-beans>

      <ejb-ref>
      <ejb-name>HelloWorld</ejb-name>
      server.HelloWorldHome
      server.HelloWorld
      <ejb-class>server.HelloWorldBean</ejb-class>
      <session-type>Stateless</session-type>
      </ejb-ref>

      </enterprise-beans>
      </ejb-jar>

      and jboss.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3//EN"
      "http://www.jboss.org/j2ee/dtds/jboss-web_3_0.dtd">

      <enterprise-beans>

      <ejb-name>HelloWorld</ejb-name>
      <ejb-ref>
      <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
      <jndi-name>ejb/HelloWorld</jndi-name>
      </ejb-ref>

      </enterprise-beans>




      Project.jar :

      package server;
      /**
      * This is the remote interface that the client calls to
      * have the EJB do the work.
      */
      public interface HelloWorld extends javax.ejb.EJBObject
      {
      public String hello() throws java.rmi.RemoteException;
      }

      package server;
      import javax.ejb.SessionContext;
      /**
      * This class is the actual implementation of the business
      * logic. This is the EJB for simplicity's sake.
      */
      public class HelloWorldBean implements javax.ejb.SessionBean
      {
      private SessionContext ctx;
      public void setSessionContext(SessionContext ctx)
      {
      this.ctx = ctx;
      }
      public void ejbRemove()
      {
      System.out.println( "ejbRemove()" );
      }
      public void ejbActivate()
      {
      System.out.println( "ejbActivate()" );
      }
      public void ejbPassivate()
      {
      System.out.println( "ejbPassivate()" );
      }
      /**
      * The method called to display the string "Hello World!"
      * on the client.
      */
      public String hello()
      {
      System.out.println( "hello()" );
      return "Hello World!";
      }
      }


      package server;
      /**
      * HelloWorldHome provides the container the means to
      * create and destroy EJB's.
      */
      public interface HelloWorldHome extends javax.ejb.EJBHome
      {
      HelloWorld create() throws java.rmi.RemoteException,
      javax.ejb.CreateException;
      }




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

          If you go to http://localhost:8080/jmx-console find the JNDI View MBean and invoke the list operation you will be able to see what is bound to JNDI so that you can identify the correct name.

          The solution to your problem will probably be to skip the java:/comp/env part of the lookup and just lookup 'ejb/HelloWorld'

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

            I've performed list() operation on MBean View this is the result:
            Anyway on java Namespace I can only see the "comp" Object,
            no way to have information about my HelloWorldBean

            Thanks in advance

            java: Namespace

            +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
            +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
            +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
            +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
            +- comp (class: javax.naming.Context)
            +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
            +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
            +- jaas (class: javax.naming.Context)
            | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
            | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
            | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
            +- timedCacheFactory (class: javax.naming.Context)
            Failed to lookup: timedCacheFactory, errmsg=null
            +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
            +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
            +- Mail (class: javax.mail.Session)
            +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
            +- TransactionManager (class: org.jboss.tm.TxManager)


            Global JNDI Namespace

            +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
            +- jmx (class: org.jnp.interfaces.NamingContext)
            | +- invoker (class: org.jnp.interfaces.NamingContext)
            | | +- RMIAdaptor (proxy: $Proxy39 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
            | +- rmi (class: org.jnp.interfaces.NamingContext)
            | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
            +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
            +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
            +- UserTransactionSessionFactory (proxy: $Proxy12 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
            +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
            +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
            +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
            +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
            +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
            +- queue (class: org.jnp.interfaces.NamingContext)
            | +- A (class: org.jboss.mq.SpyQueue)
            | +- testQueue (class: org.jboss.mq.SpyQueue)
            | +- ex (class: org.jboss.mq.SpyQueue)
            | +- DLQ (class: org.jboss.mq.SpyQueue)
            | +- D (class: org.jboss.mq.SpyQueue)
            | +- C (class: org.jboss.mq.SpyQueue)
            | +- B (class: org.jboss.mq.SpyQueue)
            +- topic (class: org.jnp.interfaces.NamingContext)
            | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
            | +- testTopic (class: org.jboss.mq.SpyTopic)
            | +- securedTopic (class: org.jboss.mq.SpyTopic)
            +- console (class: org.jnp.interfaces.NamingContext)
            | +- PluginManager (proxy: $Proxy40 implements interface org.jboss.console.manager.PluginManagerMBean)
            +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
            +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
            +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
            +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
            +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)

            • 3. Re: javax.naming.NameNotFoundException: comp not bound
              darranl

              Are you sure you have deployed the bean? Were any errors reported during deployment or when JBoss started?

              The bean should be registered in the global namespace, this namespace is accessible remotely.

              The java: namespace is for items that can only be accessed from the JVM JBoss is running in.

              • 4. Re: javax.naming.NameNotFoundException: comp not bound
                jboss_anto

                I thin so this is JBoss Log when I deploy Project.ear

                18:36:58,736 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
                18:36:59,129 INFO [EARDeployer] Init J2EE application: file:/home/acedrone/J2EE/jboss-4.0.3/server/default/deploy/Project.ear
                18:36:59,199 INFO [EARDeployer] Started J2EE application: file:/home/acedrone/J2EE/jboss-4.0.3/server/default/deploy/Project.ear
                18:36:59,450 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
                18:37:00,124 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009
                18:37:00,205 INFO [JkMain] Jk running ID=0 time=0/211 config=null
                18:37:00,218 INFO [Server] JBoss (MX MicroKernel) [4.0.3 (build: CVSTag=JBoss_4_0_3 dat