1 Reply Latest reply on Sep 4, 2002 9:27 PM by David Jencks

    JNDI DS naming conventions: Am I crazy?

    J Ramos Newbie

      Hi Everyone:

      I'm trying to to find some sort of definite answer to this dilemma. This not a "does not work" type problem, more of a "would like to know a better way" type deal :)

      I have a web application (WAR) that requires a DataSource. Naturally, I'd like to maintain a simple and consistent way of acquiring that DS through JNDI, but that seems to be either not easy, or impossible, or I just plain don't know(more probable than anything)...

      What I mean is that, if I have a DS defined as:

      jdbc/DataSource

      under ANY app Server/web container, I'd like to acquire it by using just that name, not some variant of

      java:/ (jboss)
      java:comp/env (Tomcat and many others)

      I've scoured the group, and I found a suggestion of using jboss.xml. I created one like this:


      <resource-managers>
      <resource-manager res-class="">
      <res-name>jdbc/DataSource</res-name>
      <res-jndi-name>java:/jdbc/DataSource</res-jndi-name>
      </resource-manager>
      </resource-managers>


      and placed it under the MANIFEST-INF directory of my WAR.
      The Datasource happens to be a mySQL, but I think that's beside the point. So, the excerpt of that service file is:

      <mbean code="org.jboss.resource.connectionmanager.LocalTxConnectionManager" nam
      e="jboss.jca:service=LocalTxCM,name=DataSource">

      ....

      jdbc/DataSource
      ....


      With this, jboss starts and prints the message that my datasource is bound to java:/jdbc/DataSource. If I write my code as:

      DataSource ds = (DataSource)ctx.lookup("java:/jdbc/DataSource");

      everyone's happy, but if I try to write it as:

      DataSource ds = (DataSource)ctx.lookup("jdbc/DataSource");

      I get the dreaded "jdbc Not bound" message.

      --> Is this a "solvable" problem, and if so, can anyone show me how?

      Thanks for bearing with me :)

      Best Regards,
      J Ramos

        • 1. Re: JNDI DS naming conventions: Am I crazy?
          David Jencks Master

          I don't think you'll ever find a way to get rid of java:/ at the start, because, really, there is no way to access it outside the vm it is deployed in.

          I think there is a way of using java:/comp/env/something indirection from servlets and maybe jsps, but I don't know what it is. Maybe there's a jboss-web.xml file. Anyway, the web/jsp forum is more likely to give you good hints for this.