2 Replies Latest reply on Dec 24, 2002 3:11 AM by winestr

    Object from context

    winestr

      I am trying to get my own data access pool class from the ebj context.

      I have inserted the jar containing the required classes in
      %JBOSS_HOME%\server\default\lib


      In the ejb-jar.xml

      <resource-env-ref>
      <description />
      <resource-env-ref-name>
      dataSource
      </resource-env-ref-name>
      <resource-env-ref-type>
      com.access.AccessDataSource
      </resource-env-ref-type>
      </resource-env-ref>


      In the jboss.xml


      <resource-env-ref>
      <resource-env-ref-name>
      dataSource
      </resource-env-ref-name>
      <jndi-name>
      mysource
      </jndi-name>
      </resource-env-ref>


      and in the bean I have used the code

      try
      {
      java.util.Hashtable JNDIParm =
      new java.util.Hashtable();
      JNDIParm.put(Context.PROVIDER_URL, "localhost");
      JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      Context c = new InitialContext(JNDIParm);

      Object d = c.lookup("java:comp/env/mysource");
      }
      catch (NamingException e)
      {
      e.printStackTrace();
      }


      but this only gives a NameNotFoundException.

      Can anyone show me what I have done wrong?

      Thanks

      Ray

        • 1. Re: Object from context

          Remove providerurl for a start.
          Use new InitialContext()

          Regards,
          Adrian

          • 2. Re: Object from context
            winestr

            I have changed my code to
            Context c = null;
            Object d;
            /**@todo Complete this method*/
            try
            {
            c = new InitialContext();
            d = c.lookup("mysource");
            }
            catch (NamingException e)
            {
            try
            {
            d = c.lookup("java:mysource");
            }
            catch (NamingException e1)
            {
            try
            {
            d = c.lookup("java:comp/env/mysource");
            }
            catch (NamingException e2)
            {
            e2.printStackTrace();
            }
            }
            }

            but still do have any success

            Regards

            Ray